在谷歌地图上更改标记位置的缩放?

时间:2014-06-16 01:35:16

标签: javascript api maps

地址标记已放大。如何让单个标记的缩放更远?如果有人可以提供帮助那就太棒了!这是我的JavaScript。谢谢你的帮助

$('#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);
        });            

1 个答案:

答案 0 :(得分:0)

找出有效的方法。我在map.fitBounds(bounds)之前添加了这段代码;它起作用了:

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