Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

javascript - Remove marker in Google Maps Api v3

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 ...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

RemovingOverlays

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

... for path:

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

PolylineOptions, MVCArray.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...