This my code.
I get data from xml.
But it’s not working..
Please look it where is there error.
I can’t find it.. I am working on it for more than a week…
But nothing:(
P.S. Sorry for my English..
This is my XML data..
<marker>
<line id_line="1" colour="#ccc" width="4" users="line" coordinats="47.828979,40.974844;47.839451,40.985211;47.848377,40.981064;47.853699,40.984822">
<point lng="40.974844" lat="47.828979"/>
<point lng="40.985211" lat="47.839451"/>
<point lng="40.981064" lat="47.848377"/>
<point lng="40.984822" lat="47.853699"/>
</line>
</marker>
JavaScript:
function line() {
var point=[];
downloadUrl("line.php", function(data) {
var xml = data.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
var lines = xmlDoc.documentElement.getElementsByTagName("line");
for (var a = 0; a < lines.length; a++) {
var colour = lines[a].getAttribute("colour");
var width = parseFloat(lines[a].getAttribute("width"));
var points = lines[a].getElementsByTagName("point");
alert (points[i].getAttribute("lat"));
var pts = [];
for (var i = 0; i < points.length; i++) {
pts[i] = new google.maps.LatLng(parseFloat(points[i].getAttribute("lat")),
parseFloat(points[i].getAttribute("lng")));
}
new google.maps.Polyline(pts,colour,width);
pts.setMap(map);
}
google.maps.event.addListener(pointpath,'mouseover', function() {
this.setOptions({strokeColor: '#3ADF00' });
this.setOptions({strokeOpacity: 1.0 });
this.setOptions({strokeWeight: 4 });
});
google.maps.event.addListener(pointpath,'mouseout', function() {
this.setOptions({strokeColor: '#FF0040' });
this.setOptions({strokeOpacity: 1.0 });
this.setOptions({strokeWeight: 2 });
});
var mpenc = new google.maps.InfoWindow();
var contentString = "Status: " + status ;
google.maps.event.addListener(pointpath,'click', function(event) {
mpenc.setContent(contentString);
mpenc.setPosition(event.latLng);
mpenc.open(map);
});
}
});
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
}
What is xmlDoc supposed to be?
Looks like this line:
should be:
If that doesn’t help, see this tutorial in the Google Maps API v3 documentation, the section “Outputting XML with PHP” and the part about checking that the XML output works.
Make sure you have this line:
And the headers include the correct content type. Open the XML in your browser and/or run it through a validator (requestXML will be null if the XML is not valid).
Example with slightly modified xml