Google Maps API v3: How to remove all markers?

后端 未结 30 3400
悲哀的现实
悲哀的现实 2020-11-22 05:36

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 A

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 06:11

    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

    markersArray.push(newMarker) ;
    while(markersArray.length) { markersArray.pop().setMap(null); }
    
    // No need to clear the array after that.
    

提交回复
热议问题