最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove marker in Google Maps Api v3 - Stack Overflow

programmeradmin0浏览0评论

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

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

Share Improve this question edited Jul 17, 2011 at 20:52 rebeliagamer 1,27817 silver badges33 bronze badges asked Jul 17, 2011 at 19:01 fillibusterfillibuster 6984 gold badges16 silver badges33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

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)

  1. 暂无评论