I have a HTML page which hosts a google maps info control. I am able to display a marker giving static values hard-coded in the html document. Now i am trying to get the values from a XML external source document. This is what I want to do,
function initialize(Object) {
var mapOptions = {
center: new google.maps.LatLng(19.314059,84.801407),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
marker:true
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
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","cd_catalog.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("CD");
for (i = 0; i < x.length; i++) {
var LatLat = x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue;
var LongLong = x[i].getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue;
var Title = x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue;
var myLatlng = new google.maps.LatLng(LatLat, LongLong);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: Title
});
}
}
The xml document,
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<CATALOG>
<CD>
<TITLE>Ambupa Bauri Street</TITLE>
<ARTIST>56</ARTIST>
<COUNTRY>19.3173287566233</COUNTRY>
<COMPANY>84.8497137612449</COMPANY>
</CD>
<CD>
<TITLE>Anadrigam</TITLE>
<ARTIST>64</ARTIST>
<COUNTRY>19.3128836507433</COUNTRY>
<COMPANY>84.7996238277367</COMPANY>
</CD>
</CATALOG>
My tag is as below,
<body onload="if (onLoad) onLoad(); initialize()">
This is not working, any help will be appreciated.