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?
Looking at the Reference API, it's unclear to me.
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?
Looking at the Reference API, it's unclear to me.
Just walk over markers and remove them from map, empty maps markers array after that:
I don't think there is one in V3 so I used the above custom implementation.
Disclaimer: I did not write this code but I forgot to retain a reference when I merged it into my codebase so I don't know where it came from.
Simply do the following:
I. Declare a global variable:
II. Define a function:
OR
III. Push markers in the 'markerArray' before calling the following:
IV. Call the
clearOverlays();
ormap.clearOverlays();
function wherever required.That's it!!
A clean and easy application of rolinger's answer.
It seems that there is no such function in V3 yet.
People suggest to keep references to all markers you have on the map in an array. And then when you want to delete em all, just loop trough the array and call .setMap(null) method on each of the references.
See this question for more info/code.
My version:
The code is edited version of this code http://www.lootogo.com/googlemapsapi3/markerPlugin.html I removed the need to call addMarker manually.
Pros
Cons
This was the most simple of all the solutions originally posted by YingYang Mar 11 '14 at 15:049 under the original response to the users original question
I am using his same solution 2.5 years later with google maps v3.18 and it works like a charm