Sometimes, we want to remove an event listener with Google Maps API v3.
In this article, we’ll look at how to remove an event listener with Google Maps API v3.
How to remove an event listener with Google Maps API v3?
To remove an event listener with Google Maps API v3, we can call the removeListener method.
For instance, we write
const listenerHandle = google.maps.event.addListener(
map,
"bounds_changed",
() => {
//...
}
);
google.maps.event.removeListener(listenerHandle);
to call addListener to add the bound_changed event listener onto the map.
It returns the listenerHandle object that we call removeListener with to remove it when we don’t need to listen to the bounds_changed event on the map.
Conclusion
To remove an event listener with Google Maps API v3, we can call the removeListener method.