简体   繁体   中英

Google Maps API v3: Is there a callback or event listener after zoom changed?

The Google maps API v3 has a callback on map zoom_changed but that gets triggered before the zoom starts (when I click the zoom in/out button). The state of the map inside the callback function is the one before zooming, I want the one after the zoom.

Is there such a callback?

Thanks

Edit: The link was deleted.

It seems like a bug in the API.

What most people try to do is basically the following:

google.maps.event.addListener(map,'zoom_changed',function (event) {
    // some handling code here
});

But that won't work as the event fires before the bounds change. What is suggested to do in this case is the following:

zoomChangeListener = google.maps.event.addListener(map,'zoom_changed',function (event) {
    zoomChangeBoundsListener = google.maps.event.addListener(map,'bounds_changed',function (event) {  
      console.log(map.get_bounds());
      google.maps.event.removeListener(zoomChangeBoundsListener);
    });
});

So now, after the zoom_changed event fires, we actually set another listener, this time for the bounds_changed event, so at the time of this event firing, we are sure that the bounds have changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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