> the problem is not the alert();
>
> The route are not shown until i do the alert() on this position.
I know. It is because the downloadUrl is asynchronous. The code that
follows on from the callback is executed BEFORE the data XML has been
fetched. Later on, the XML arrives and is processed, but it is too
late ; your code that tries to use the XML waypts has already been run
with an empty array.
downloadUrl( url , function .... ) // issues a request for XML
var request = { ... waypoints: waypts, ... } // uses an empty
array
directionsService.route(request, function ... ) // issues a
directions request with empty waypts
Much later .... XML data arrives and is processed
... var xml = parseXml(data);
At some other time, maybe before or maybe after the XML, the
directions data arrives and is processed
... directionsDisplay.setDirections(response);
When you add the alert it stops that branch of code until you press
'enter', which allows time for the XML to be fetched.
If you want to use data from an asynchronous function, you must use it
inside that functions callback.
downloadUrl("mapxml.php?action=loadintour&id="+id+"",
function(data)
{
var xml = parseXml(data);
...
var request = { ... waypoints: waypts, ... }
directionsService.route(request, function {
...
} ) // end directions callback
} ) // end downloadurl callback
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.