简体   繁体   中英

How to refresh all markers in google maps v3?

I want to be able to refresh all the markers every minute. This means the existing markers should be deleted parse again the data from the xml file and draw them again on the map. It apears that map.clearOverlays(); isn't working on v3 and I should interate among the markers to delete them some how.

Which is the right syntax to delete the existing markers and load new ones on a given time interval?

for (i = 0; i < markerArray.length; i++) {
     markerArray[i].setMap(null);
}

That will delete every marker from the map.

Basically you need to use marker.setMap(null); See Google Maps API v3: How to remove all markers?

You'll want to do this in conjunction with setTimeout(), and another routine to add your markers (I assume if you've got this far you know how to add a marker already).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM