Google Maps API v3:缩放后有没有回调或事件侦听器? [英] Google Maps API v3: Is there a callback or event listener after zoom changed?

查看:92
本文介绍了Google Maps API v3:缩放后有没有回调或事件侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌地图API v3在地图zoom_changed上有一个回调,但在缩放开始之前(当我点击放大/缩小按钮时)触发。回调函数中的映射的状态是缩放之前的映射的状态,我想要在缩放之后的映射。



是否有这样的回调?

p>

谢谢 解决方案

编辑:链接被删除。



这看起来像是API中的一个错误。



大多数人试图做的基本上如下:



pre $ lt; code> google.maps.event.addListener(map,'zoom_changed',function(event){
//一些处理代码here
});

但是,当事件在边界更改之前触发时,这不起作用。在这种情况下建议做的事情如下:

  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);
});
});

现在,在 zoom_changed 事件触发后,我们实际上设置了另一个监听器,这次是 bounds_changed 事件,所以在这个事件触发时,我们确信边界已经改变了。


The Google maps API v3 has a callback on map zoom_changed but that gets triggered when I the 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 the zoom, I want the one that will be 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.

这篇关于Google Maps API v3:缩放后有没有回调或事件侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆