开发者

Remove marker in Google Maps Api v3

开发者 https://www.devze.com 2023-03-20 18:05 出处:网络
I\'m using this function to add a new marker (and polyline) to a map: function addMarker(location) { path = poly.getPath();

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.ma开发者_如何学运维ps.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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消