Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(_???_);     
like image 971
mp_ Avatar asked Oct 09 '09 14:10

mp_


People also ask

How do I remove a specific event listener?

Event listeners can also be removed by passing an AbortSignal to an addEventListener() and then later calling abort() on the controller owning the signal.

Do I need to remove an event listener?

If there is no memory leak, the used memory will increase by around 1000kb or less after the tests are run. However, if there is a memory leak, the memory will increase by about 16,000kb. Removing the event listener first always results in lower memory usage (no leaks).


1 Answers

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.

like image 120
Maiku Mori Avatar answered Sep 28 '22 03:09

Maiku Mori