Check out this informative example by a gentleman showcasing the use of GDownloadUrl:
If you encounter errors in Chrome, try adding the responseCode parameter to your callback function. It's recommended to ensure that you are using the latest version of Chrome for compatibility with this example.
Take a look at his code snippet below:
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
// Fetch data from data.xml and display it on the map. Expected format:
// <markers>
// <marker lat="37.441" lng="-122.141"/>
// <marker lat="37.322" lng="-121.213"/>
// </markers>
GDownloadUrl("data.xml", function(data, responseCode) {
// Verify status code is 200 before processing data
if(responseCode == 200) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
map.addOverlay(new GMarker(point));
}
} else if(responseCode == -1) {
alert("Data request timed out. Please try later.");
} else {
alert("Request resulted in error. Check XML file availability.");
}
});
}
}