Google Maps JavaScript API - Automate Zoom Level?

后端 未结 5 898
执念已碎
执念已碎 2020-12-15 14:01

I\'m working with multiple map markers. Currently I use map.fitBounds(bounds); in my JavaScript to resize the map. bounds contains multiple LatLng

5条回答
  •  遥遥无期
    2020-12-15 14:04

    I got here using a "Related" link to the right, and I think that the answer to your problem is the same as to the previous question. :p

    See, the thing is that every time you use a function that pans/zooms the map, the script ignores new, similar, input until it's ready for it again. Therefore, you have to detect this and only call fitBounds() when it's accepted. Try replacing your

    map.fitBounds(bounds);
    

    with

    var listener = google.maps.event.addListener(map, "idle", function() { 
                   map.fitBounds(bounds);
                   google.maps.event.removeListener(listener); });
    

    Good luck.

提交回复
热议问题