i have been struggling code quite time. loading xml google maps , geocoding addresses xml. need add delay code when there many addresses @ once.
here entire code doing this
i need have load xml file delay, loads @ once , geocoder can not handle many requests when xml large. xml file changing continuously needs reloaded , re-geocoded. becomes problem when xml file becomes larger, when need work most.
i have placed delay around geocoder.getlocations(address,createmarker);
address variable contains addresses not delay it. if place delay around var address = markers[i].getattribute("address");
not pass i
variable function. can give appreciated.
// create marker function createmarker(response) { var place = response.placemark[0]; var point = new glatlng(place.point.coordinates[1], place.point.coordinates[0]); var marker = new gmarker(point); gevent.addlistener(marker, "click",function() { marker.openinfowindowhtml(place.address); }); map.addoverlay(marker); } // create new map object var map = new gmap2(document.getelementbyid("map")); map.addcontrol(new gsmallmapcontrol()); map.addcontrol(new gmaptypecontrol()); map.enablescrollwheelzoom(); map.addmaptype(g_physical_map); map.setcenter(new glatlng(49.923068,-119.437981), 10); var geocoder = new gclientgeocoder(); // download data in active.xml gdownloadurl("active.xml", function(data) { var xml = gxml.parse(data); var markers = xml.documentelement.getelementsbytagname('inc'); settimeout( function() { (var = 0; < markers.length; i++) { var address = markers[i].getattribute("address"); geocoder.getlocations(address,createmarker); } },200); });
try:
for (var = 0; < markers.length; i++) { var address = markers[i].getattribute("address"); function (inneraddress, j) { settimeout(function() { geocoder.getlocations(inneraddress,createmarker); }, 200 * j); }(address, i); }
this should space out requests geocoder.
Comments
Post a Comment