Javascript google maps creating markers from xml data



-i have this code and I am testing it on Mozilla. This code should make large number of markes on map. I have my latitude and longitude for markers in XML file. When it run it it freeze the browser sor a few second and make only 15 markers. Console says this "too much recursion". I tried also use for(var i =0;i < x.length;i++) cycle but result was same except I didnt get "too much recursion" in console.



var map;
var i =0;
var xmldoc=loadXMLDoc("skoly.xml");
var x= xmldoc.getElementsByTagName("skoly");
var image = {url: 'images/blackmarker.png',
anchor: new google.maps.Point(0, 10)};

function loop(){

createMarker(function(){loop();});
}

function createMarker(callback) {
var location =new google.maps.LatLng (xmldoc.getElementsByTagName("gps_latitude")[i].childNodes[0].nodeValue,xmldoc.getElementsByTagName("gps_longitude")[i].childNodes[0].nodeValue);
var marker = new google.maps.Marker({
position: location,
map:map,
icon: image
});
i++;
if(i < x.length)callback();
}

function initialize() {
var startlatlng = new google.maps.LatLng(49.8037633,15.4749126,7);
var mapOptions = {
zoom: 7,
center: startlatlng
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
loop();
}
google.maps.event.addDomListener(window, 'load', initialize);

No comments:

Post a Comment