Hi there!

I'm trying to get some coordinates from a database, insert them into a
XML file and them show them on the map, snapped to the nearest road.

The thing is I am having problems because the asynchronous thing.

What's the best option to avoid/step over it?

I read setTimeout is not the best choice, but even that I'm unable to
make work... =(

I'm doing this locally, so there's no link to a website. =/

Here's my code:

// This is the array of locations. It's "hand made" now, but it' will
be dynamic, loaded from the XML file
var points = [];
points[0] = new GLatLng(39.761616,-8.804662);
points[1] = new GLatLng(39.734353,-8.773785);
points[2] = new GLatLng(39.740363,-8.810359);

i=0;
while(i < points.length)
{
alert(i);
if (firstpoint)
{
dirn.loadFromWaypoints([points[i],points[i]],{getPolyline:true});
firstpoint = false;
}
else
{
dirn.loadFromWaypoints([points[i-1],points[i]],{getPolyline:true});
}

GEvent.addListener(dirn,"load", function()
{
// snap to last vertex in the polyline
var n = dirn.getPolyline().getVertexCount();
var p = dirn.getPolyline().getVertex(n-1);
var marker=new GMarker(p);
map.addOverlay(marker);
gmarkers.push(marker);
if (!firstpoint)
{
map.addOverlay(dirn.getPolyline());
gpolys.push(dirn.getPolyline());
}
});
i++;
}


If my only alternative was to use setTimeout, where would I put it?
Which function would it call?

Thanks guys!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to