简体   繁体   English

Google Maps API v3:缩放更改后是否有回调或事件侦听器?

[英]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).谷歌地图 API v3 对地图zoom_changed有一个回调,但在缩放开始之前被触发(当我点击放大/缩小按钮时)。 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.这似乎是 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.所以现在,在zoom_changed事件触发后,我们实际上设置了另一个监听器,这次是为bounds_changed事件设置,所以在这个事件触发时,我们确定边界已经改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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