Remove marker in Google Maps Api v3

2019-01-26 05:27发布

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 ...

2条回答
beautiful°
2楼-- · 2019-01-26 06:13

Last Marker is at the index of markersArray.length -1 so...

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

查看更多
\"骚年 ilove
3楼-- · 2019-01-26 06:30

RemovingOverlays

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

... for path:

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

PolylineOptions, MVCArray.

查看更多
登录 后发表回答