I use an xmlhttprequest to get coordinates out of a mysql database. This works with the following code:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://skyline-va.de/phpvms/lib/skins/crystal/mysql.php?id="+this.flightdetails.id,true);
xmlhttp.send();
Looking at the firebug console I see that this outputs the data in this format
new google.maps.LatLng(51.2848358165405, 6.77062893232108),
new google.maps.LatLng(51.2848358165405, 6.77062893232108),
new google.maps.LatLng(51.2848358165405, 6.77062893232108),
new google.maps.LatLng(51.2848358165405, 6.77062893232108),
and so on.
But how can I use this to display a polyline in Google Maps api? I've already tried searching google, unfortunately I couldn't find anything useful. I've also tried several things without success.
Thanks!
EDIT:
Here is the map I am working on right now:
http://skyline-va.de/phpvms/index.php/acars/viewmapbig
Basically what I want to do is if you click on one of the planes, the flightpath should be displayed as well. I have the coordinates stored in a database but I have to do the query after the plane is clicked.
EDIT2: I managed to output the data in xml format with the google documentary. But I can't get the code to work supplied by Google to display the data. I want to add every new point that comes through the for command to an array.
function downloadUrl(url,callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.open('GET', url, true);
request.send(null);
}
var flightPlanCoordinates = [
];
downloadUrl("http://skyline-va.de/phpvms/lib/skins/crystal/output-xml.php?id="+this.flightdetails.id, function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
flightPlanCoordinates.push(new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng"))));
};
});
flightPath2 = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2
});
flightPath2.setMap(map);
But that doesn't seem to work.
I've finally managed to get everything working now. The solution is this code:
Thanks to everyone who helped to solve this problem!