Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

javascript - Google Maps API v3: How to remove an Event Listener?

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

google.maps.event.removeListener(_???_);    
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...