Javascript 在 Google Maps Api v3 中删除标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6726049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove marker in Google Maps Api v3
提问by fillibuster
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 ...
此致 ...
回答by rebeliagamer
markersArray[markersArray.length-1].setMap(null);
... for path:
...对于路径:
path = poly.getPath();
path.pop();
回答by trs
Last Marker is at the index of markersArray.length -1
so...
最后一个标记位于markersArray.length -1
so...
markersArray[markersArray.length-1].setMap(null);
markersArray[markersArray.length-1].setMap(null);