Skip to content Skip to sidebar Skip to footer

Any Simple Way To Clean All Markers, Polylines And Other Overlays On Google Maps V3 Api?

I want to get a new map not using refush the webpage. thanks and has easy way to get all Overlays on the map?

Solution 1:

In the v2 API, there was the clearOverlays() method as Gaby pointed out. However, this method is not present if the v3 API. If I remember correctly, this omission was intentional to keep the library lightweight.

Therefore, with the v3 API, you have to keep a reference of your overlays, and then call setMap(null) on each overlay.

Solution 2:

FYI for peoples using V3: From what I have found, V3 does not have a packaged function like V2 does in .clearOverlays();

Here is what I do (as I've gathered from other resources):

var gmarkers = []; // establish your markers array;if (gmarkers) { // plug this in wherever/whenever you want to clear the map of any and all markers;for (i in gmarkers) {
        gmarkers[i].setMap(null);
    }
    gmarkers.length = 0;
}

Solution 3:

Post a Comment for "Any Simple Way To Clean All Markers, Polylines And Other Overlays On Google Maps V3 Api?"