简体   繁体   English

更改Google地图上标记位置的缩放?

[英]Changing zoom for marker location on google map?

The marker for the address is zoomed in. How can I get the zoom to be farther out for a single marker? 地址的标记已放大。如何使单个标记的变焦更远? If anyone can help that would be awesome! 如果有人可以帮助,那就太好了! Here is my JavaScript. 这是我的JavaScript。 thanks for any help 谢谢你的帮助

$('#map_here').prepend('<div id="map"></div>');
        $(".static_map").remove();

    var map;
    var bounds;
    var geocoder;
    var center;

    function initialize() {
        var mapOptions = {
            center: new google.maps.LatLng(-34.397, 150.644),
            zoom: 5
        };
        map = new google.maps.Map(document.getElementById("map"),
        mapOptions);
        geocoder = new google.maps.Geocoder();
        bounds = new google.maps.LatLngBounds();
    }
    function addMarkerToMap(location){
        var marker = new google.maps.Marker({map: map, position: location});
        bounds.extend(location);
        map.fitBounds(bounds);
    }
    initialize();

    $("address").each(function(){
        var $address = $(this);
        geocoder.geocode({address: $address.text()}, function(results, status){
            if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(results[0].geometry.location);
        });
    });

    google.maps.event.addDomListener(map, "idle", function(){
        center = map.getCenter();
    });

     $(window).resize(function(){
            map.setCenter(center);
        });            

Found out what worked. 找出有效的方法。 I added this code before map.fitBounds(bounds); 我在map.fitBounds(bounds);之前添加了此代码。 and it worked: 它的工作原理是:

google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
    if (this.getZoom() > 15) {
          this.setZoom(15);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM