Google Maps API v3: How to remove all markers?

后端 未结 30 3615
悲哀的现实
悲哀的现实 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:24

    google.maps.Map.prototype.markers = new Array();
    
    google.maps.Map.prototype.addMarker = function(marker) {
        this.markers[this.markers.length] = marker;
    };
    
    google.maps.Map.prototype.getMarkers = function() {
        return this.markers
    };
    
    google.maps.Map.prototype.clearMarkers = function() {
        for(var i=0; i

    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.

提交回复
热议问题