Google Maps API v3: Can I setZoom after fitBounds?

前端 未结 23 2473
执笔经年
执笔经年 2020-11-27 09:35

I have a set of points I want to plot on an embedded Google Map (API v3). I\'d like the bounds to accommodate all points unless the zoom level is too low (i.e., zoomed out

23条回答
  •  粉色の甜心
    2020-11-27 10:00

    I have come to this page multiple times to get the answer, and while all the existing answers were super helpful, they did not solve my problem exactly.

    google.maps.event.addListenerOnce(googleMap, 'zoom_changed', function() {
        var oldZoom = googleMap.getZoom();
        googleMap.setZoom(oldZoom - 1); //Or whatever
    });
    

    Basically I found that the 'zoom_changed' event prevented the UI of the map from "skipping" which happened when i waited for the 'idle' event.

    Hope this helps somebody!

提交回复
热议问题