I have a global array in my script that obtains its values from a specific function call. See the example:
var myglobalArray = [];
.
.
.
function createMarkersToFillArray(property1, property2) {
var marker= new google.maps.Marker({ position: latlng, map: map });
marker.property1 = property1;
marker.property2 = property2;
myGlobalArray.push(marker);
return marker;
}
function getStuffFromXMl() {
downloadUrl("myXMLFile.xml", function (data) {
var xmlItems = data.documentElement.getElementsByTagName("row");
for (var i = 0; i < xmlItems.length; i++) {
var property1= xmlItems[i].getAttribute("Property");
var property2 = xmlItems[i].getAttribute("Property2");
var marker = createMarkersToFillArray(property1, property2);
}
});
}
The code above is doing exactly what I expected it to do. The problem occurs when I try to access myGlobalArray
's elements inside the initialize()
function.
function initialize() {
getStuffFromXML(); //this should populate myGlobalArray with the markers, but it doesn't
}
It says that the array is empty, even though the markers are being added into the array. Could someone explain why myGlobalArray
's elements appear to vanish when I try to access them inside the initialize()
function?