I've set up a marker with a click event listener attached to it. However, I want to check if the click event has already been added to the marker, and if not, add the click event listener.
// Add click event listener if it doesn't already exist
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
Alternatively, I can use a custom flag in the marker object like this:
// Add click event listener if it doesn't already exist
if (! marker._isClickEventBound) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
marker._isClickEventBound = true;
});
}
This code is run when a new marker is added or when editing an existing marker. I'm just wondering if there's a way to achieve this without using a flag?