0

I have the next code for loading a path using a xml file, but when I try to load another path for other vehicle, it load also the last path together with the new one. Before load the XML file again I firstly call a remove function. But it only hide the path .

Best regards.

var polyline = [];

function path() {


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

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

//new polyline

polyline.setMap(map);

}); //end download url
}

function removePath() {

polyline.setMap(null);
polyline = null;
}
Fran Rod
  • 586
  • 4
  • 14
  • 26
  • You code currently will not do anything, because there is no variable path. Please show use your current code, because when I uncomment `//var path = [];` your code works as expected. – Dr.Molle Nov 25 '12 at 18:42
  • Perfect, I uncommented it and now it is working. Thank you! – Fran Rod Nov 25 '12 at 20:42

0 Answers0