Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API v3 - How to clear overlays?

Tags:

In Google Maps API v2, I was using map.clearOverlays() to remove the marker and draw them again.

How can I do that using Google Maps API v3 ?

Thanks

like image 960
Natim Avatar asked Jun 01 '10 08:06

Natim


People also ask

How do you remove map markers?

Click the marker to reveal the editing options. Click the "Delete" link in the lower-left corner of the dialog box.


1 Answers

This is good one:

http://apitricks.blogspot.com/2010/02/clearoverlays-in-v3.html

Article in case the link dies:

clearOverlays() in V3

There is no clearOverlays() in API v3. Some practices have been presented. I think this is the simpliest so far.

Push all the overlays in an array when created (as usual). Following code will clear both map and the array:

while(overlays[0]) {   overlays.pop().setMap(null); } 

pop() method of an array removes the last element of an array, and returns that element. 'while' keeps that happening as long as there are elements in the array. When overlays[0] does not exist anymore, the mission is completed and code will proceed.

like image 151
Emmanuel Umaña Avatar answered Nov 08 '22 16:11

Emmanuel Umaña