Your eventListener call is correct, just not in the right place in your code. I added a few warnings to the eventListener to find out what is happening, and if you see the second warning, the markers are actually cleared - but as soon as the warning window closes, the markers reappear. Try it yourself:
google.maps.event.addListener(marker_0, "dragend", function() { alert("before calling clear_markers()"); clear_markers(); alert("markers should be cleared"); });
This means that as soon as javascript is launched into your dragend event listener, it will execute the code inside - but then it will also go through the rest of the code, and therefore the markers are populated on the map again. You can fix this problem by adding an event listener to the end of your initialize() function after var markerCluster = new MarkerClusterer(map, markers, clusterOptions); .
text in italics is a wrong explanation, see answer below for the correct solution
/ ---------------------------------------------- --- -------------------------------------------- /
Ignoring my previous answer, let me change it. Again, you are calling eventListener in the correct way. You just need to add the following code snippet to the listener function to make sure the markers are not displayed.
google.maps.event.addListener(marker_0, "dragend", function() { clear_markers(); markerCluster.setMap(null); });
It seems that markerCluster initialization overrides your clear function on markers. Thus, you will also need to clear the marker cluster from your card. I apologize for the fact that you made a mistake in my previous answer, markCluster is a new concept for me.