我已经创建了一个标记数组。我使用这些标记阵列来聆听'点击'并将标记放置在Google地图上,并创建函数以“清除所有标记”,“重新显示所有标记”和“删除所有标记”。如何在谷歌地图上一次删除一个标记
问题是,我如何以一种能够清除或删除一次一个标记的方式执行此操作?原因是因为如果我碰巧无意中划到了一个我不想要的地方,而且我想清除/删除它,我无法做到这一点。如果我是清除/删除特定的标记,那我以前绘制的将被清除标记其余/删除,以及...
我的代码:
//Initialize the map
function initialize() {
var myLatlng = new google.maps.LatLng(2,110);
var myOptions = {
zoom: 3,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
infowindow = new google.maps.InfoWindow({
content: "loading..."
});
}
function changeForm(the_form) {
window.location = the_form;
}
//Listen for click
function marker() {
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
});
}
// Place markers in by click
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map,
title:"Specified Location",
icon: 'images/greenPoint.png'
});
markersArray.push(marker);
}
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
// Shows any overlays currently in the array
function showOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(map);
}
}
}