簡體   English   中英

更改Google地圖上標記位置的縮放?

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

地址的標記已放大。如何使單個標記的變焦更遠? 如果有人可以幫助,那就太好了! 這是我的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);
        });            

找出有效的方法。 我在map.fitBounds(bounds);之前添加了此代碼。 它的工作原理是:

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