deluxmilkman
Programmer
I`m putting markers on Google Mpas using maps.xml,
and I would like to include maps.xml into HTML to make it one file.
Now, I need to know how to read this XML and process.
my XML in HTML.
my Javascript for external XML file (I need to change this for embedded XML).
Thank you.
and I would like to include maps.xml into HTML to make it one file.
Now, I need to know how to read this XML and process.
my XML in HTML.
Code:
<xml id='xmldata' style='display:none;'>
<markers>
<marker lat="50.895842" lng="-1.4051" />
</markers>
</xml>
my Javascript for external XML file (I need to change this for embedded XML).
Code:
// create the map
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(50.895842,-1.4051), 14);
map.setUIToDefault();
map.enableGoogleBar();
// Read the data from example.xml
var request = GXmlHttp.create();
request.open("GET", "maps.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
// create the marker
var marker = createMarker(point;
map.addOverlay(marker);
}
}
}
request.send(null);
Thank you.