Google Maps API v3: How to remove all markers?
In Google Maps API v2, if I wanted to remove all the map markers, I could simply do:
map.clearOverlays();
How do I do this in Google Maps API v3? And how google maps clear markers?
Looking at the Reference API, it's unclear to me.
To map clear markers, you can try using the following:
1. Declare a global variable like this:
var markersArray = [];
2. Define a function like this:
function clearOverlays() {
for (var i = 0; i < markersArray xss=removed xss=removed xss=removed xss=removed>
3. Push markers in the 'markerArray' before calling the following:
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
4. Call the clearOverlays(); or map.clearOverlays(); function wherever required.