Google Maps API v3:如何删除事件监听器? [英] Google Maps API v3: How to remove an Event Listener?

查看:804
本文介绍了Google Maps API v3:如何删除事件监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Google地图API中删除bounds_changed事件侦听器v3

  google.maps.event.removeListener(_ ??? _); 


解决方案

通常,您可以在Google地图中找到这些问题的答案API文档。



正如Andrew所说,addListener返回一个句柄,稍后您可以使用它来删除该监听器。这是因为一个事件可能有很多监听器,并且要删除它们,您必须保存对每个附加监听器的引用。

还有一个函数,它可以删除所有监听器同时:

  clearListeners(instance:Object,eventName:string); 
//在你的情况下:
google.maps.event.clearListeners(map,'bounds_changed');

以下是Google Maps API参考资料,您可以在这里参阅它。


How do I remove the 'bounds_changed' Event listener in Google Maps API v3?

google.maps.event.removeListener(_???_);    

解决方案

Usually you can find answers to such questions in Google Maps API documentation.

As Andrew said, addListener returns a handle which you can use later to remove the listener. That's because a single event can have many listeners and to remove them you must save a reference to each of attached listeners.

There's also a function which removes all of the listeners at the same time:

clearListeners(instance:Object, eventName:string);
//In your case:
google.maps.event.clearListeners(map, 'bounds_changed');

Here's the Google Maps API reference where you can read about it.

这篇关于Google Maps API v3:如何删除事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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