Reputation: 7227
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
Upvotes: 1
Views: 4848
Reputation: 469
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.
Upvotes: 4