Google Maps API v3: How to remove all markers?

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

    To clear of all the overlays including polys, markers, etc...

    simply use:

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);}

    Here is a function that I wrote to do it form me on a map application:

      function clear_Map() {
        directionsDisplay = new google.maps.DirectionsRenderer();
        //var chicago = new google.maps.LatLng(41.850033, -87.6500523);
        var myOptions = {
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: HamptonRoads
        }
    
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    }
    

提交回复
热议问题