Ich habe ein Array von Markern erstellt. Ich benutze diese Anordnung von Markierungen, um auf "Klicken" zu hören und den Marker auf Google Map zu platzieren, sowie Funktionen zu erstellen, um alle Marker zu löschen, alle Marker erneut anzuzeigen und alle Marker zu löschen.So löschen Sie einen Marker auf Google Karte
Das Problem ist, wie mache ich das in einer Weise, wo ich in der Lage bin, einen Marker nach dem anderen zu löschen oder zu löschen? Der Grund ist, weil, wenn ich versehentlich an einen Ort plottete, wo ich nicht möchte, und ich würde es löschen/löschen wollen, konnte ich es nicht tun. Wenn ich löschen waren/Löschen, dass bestimmte Marker, den Rest der Markierungen, die ich vorher gelöscht werden aufgetragen haben/als auch gelöscht ...
Mein Code:
//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);
}
}
}