Hi there, I've just started with the Google Maps API and I'm already
hitting walls, I'm successfully displaying my markers like I need them,
but when i'm trying to add an Info Window that is parsed from the XML
file it always fails.
I've looked on the forums for posts with the same topic, but haven't
found any that explained what I needed.
My XML File is Formatted as such :
<markers>
<marker lat="29.431434" lng="-98.491051">
<uri>http://www.ymcasatx.org/</uri>
<name>Association Office</name>
<address>1123 Navarro</address>
<phone>210-246-9622</phone>
</marker>
<marker lat="29.536861" lng="-98.425538" desc="Northeast YMCA">
<uri>http://www.ymcasatx.org/notheast</uri>
<name>Northeast YMCA</name>
<address>1123 Navarro</address>
<phone>210-246-9622</phone>
</marker>
</markers>
and my script that calls the XML file is as such:
<script type="text/javascript">
// Center the map on Palo Alto
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(-98.491051, 29.431434), 7);
// Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "http://www.ymcasatx.org/images/map-icon.png";
icon.shadow = "http://www.ymcasatx.org/images/map-icon-shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);
var request = GXmlHttp.create();
request.open("GET", "data.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers =
xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point = new
GPoint(parseFloat(markers[i].getAttribute("lng")),
parseFloat(markers[i].getAttribute("lat")));
var marker = new GMarker(point, icon);
map.addOverlay(marker);
}
}
}
request.send(null);
//]]>
</script>
Now I dont know where to begin, I know I need to load the XML data into
a html variable, then call that variable with a listener event.
My question is can anyone point me to an already existing file where
this is done, or tell me how I can incorporate all this into my file...
Your help is GREATLY appreciated.
Thank you.
Chris