2011-07-17 6 views
12

J'utilise cette fonction pour ajouter un nouveau marqueur (et polyligne) à une carte:Supprimer marqueur dans Google Maps Api v3

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); 
} 

Comment puis-je supprimer le dernier marqueur (pour la mise en œuvre d'annuler)?

Cordialement ...

Répondre

17

RemovingOverlays

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

... pour le chemin:

path = poly.getPath(); 
path.pop(); 

PolylineOptions, MVCArray.

+0

Salut, merci. Cela fonctionne très bien pour les marqueurs, mais je ne peux pas supprimer le dernier point de la polyligne. Cordialement ... – fillibuster

+0

Maintenant, ça devrait fonctionner ... – rebeliagamer

+0

Oui fonctionne. Merci beaucoup. – fillibuster

0

dernier marqueur est à l'index de markersArray.length -1 alors ...

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

Questions connexes