Google Maps API v3: How to remove all markers?

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

    Same problem. This code doesn't work anymore.

    I've corrected it, change clearMarkers method this way:

    set_map(null) ---> setMap(null)

    google.maps.Map.prototype.clearMarkers = function() {
        for(var i=0; i < this.markers.length; i++){
            this.markers[i].setMap(null);
        }
        this.markers = new Array();
    };
    

    Documentation has been updated to include details on the topic: https://developers.google.com/maps/documentation/javascript/markers#remove

提交回复
热议问题