Question

I have the next code which show a path using a polyline. How can I remove it?

downloadUrl("myfile.asp", function(data) {
var xml = xmlParse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
var path = [];
for (var i = 0; i < markers.length; i++) {
  var lat = parseFloat(markers[i].getAttribute("lat"));
  var lng = parseFloat(markers[i].getAttribute("lng"));
  var point = new google.maps.LatLng(lat,lng);
  path.push(point);
}//finish loop

var polyline = new google.maps.Polyline({
  path: path,
  strokeColor: "#FF0000",
  strokeOpacity: 1.0,
  strokeWeight: 2
});
polyline.setMap(map);

}); //end download url

I have tried it using the next function but I m not able to make it work.

 function removePath() {
 polyline.setMap(null)

}

Was it helpful?

Solution

I think the problem is position of the variable "polyline".

var polyline = null;
downloadUrl("myfile.asp", function(data) {
   ...

   polyline = new google.maps.Polyline({
      path: path,
      strokeColor: "#FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
   });
   polyline.setMap(map);

}); //end download url

function removePath() {
  polyline.setMap(null)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top