J'ai créé un tableau de marqueurs. J'utilise ce tableau de marqueurs pour écouter «cliquer» et placer le marqueur sur Google Map, ainsi que créer des fonctions pour «effacer tous les marqueurs», «ré-afficher tous les marqueurs» et «supprimer tous les marqueurs». Le problème est, comment est-ce que je fais ceci d'une manière où je peux effacer ou supprimer un marqueur-à-la-fois? La raison est que si je me trouvais accidentellement à un endroit où je ne veux pas, et que je voudrais effacer/supprimer, je ne pouvais pas le faire. Si je devais effacer/supprimer ce marqueur particulier, le reste des marqueurs que j'ai comploté précédemment sera effacé/supprimé et ...Comment supprimer un marqueur à la fois sur google map
Mon 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);
}
}
}