简体   繁体   English

删除谷歌地图 Api v3 中的标记

[英]Remove marker in Google Maps Api v3

I'm using this function to add a new marker (and polyline) to a map:我正在使用此 function 向 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 . 折线选项MVCArray

Last Marker is at the index of markersArray.length -1 so...最后一个标记位于markersArray.length -1的索引处,所以......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM