如何从 Google 地图 delete/remove 折线?
How to delete/remove polyline from Google Map?
I'm trying to remove/delete the line.
But flightPath.setMap(null) is not working.
I'm sending the JSFiddle link which will give you complete details. of my code.
jsfiddle.net/rb9w8o5c/5/
function initialize() {
google.maps.event.addListener(map, 'click', addLatLng);
}
function addLatLng(event) {
var path = poly.getPath();
path.push(event.latLng);
marker = new google.maps.Marker({
position: event.latLng,
title: '#' + path.getLength(),
map: map
})
markers.push(marker);
for (var key in markers) {
flightPlanCoordinates.push(markers[key].position);
positions.push(markers[key].position);
}
flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
}
function removePolyline(){
flightPath.setMap(null);
}
function removePolyline(){
var path = poly.getPath();
path.pop();
marker = markers.pop();
marker.setMap(null);
for (var key in markers) {
flightPlanCoordinates.push(markers[key].position);
positions.push(markers[key].position);
}
flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
}
I'm trying to remove/delete the line. But flightPath.setMap(null) is not working. I'm sending the JSFiddle link which will give you complete details. of my code.
jsfiddle.net/rb9w8o5c/5/
function initialize() {
google.maps.event.addListener(map, 'click', addLatLng);
}
function addLatLng(event) {
var path = poly.getPath();
path.push(event.latLng);
marker = new google.maps.Marker({
position: event.latLng,
title: '#' + path.getLength(),
map: map
})
markers.push(marker);
for (var key in markers) {
flightPlanCoordinates.push(markers[key].position);
positions.push(markers[key].position);
}
flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
}
function removePolyline(){
flightPath.setMap(null);
}
function removePolyline(){
var path = poly.getPath();
path.pop();
marker = markers.pop();
marker.setMap(null);
for (var key in markers) {
flightPlanCoordinates.push(markers[key].position);
positions.push(markers[key].position);
}
flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
}