且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除Google Maps API v3中的标记

更新时间:2023-02-14 14:28:21

删除Overlay

  markersArray [markersArray.length-1] .setMap(空); 

... for path:

  path = poly.getPath(); 
path.pop();

PolylineOptions MVCArray


I'm using this function to add a new marker (and polyline) to a map:

 function addMarker(location) {

    path = poly.getPath();
    path.push(location);
    marker = new google.maps.Marker({
        position: location,
        icon:'location.png',
        title: poly.inKm() + ' km',
        map: map
    });
    markersArray.push(marker);
}

How can I remove the last marker (for implementing undo)?

Best regards ...

RemovingOverlays

markersArray[markersArray.length-1].setMap(null);

... for path:

path = poly.getPath();
path.pop();

PolylineOptions, MVCArray.