If I put dirn.loadFromWaypoints(points[i], {getPolyline:true}); inside
the loop for each point read, then the GEvent.addListener(dirn,"load",
function()) won't work...

In that case, instead GEvent.addListener(dirn,"load", function()) do I
need to have a function which will be called after all points are
read?

Something like:

var xmlDoc = GXml.parse(file);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
if(markers.length!=0)
{
        for (var i = 0; i < markers.length; i++)
        {
                // obtain the attribues of each marker
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lng = parseFloat(markers[i].getAttribute("lng"));
                var point = new GLatLng(lat,lng);
                points[i] = point;
                bounds.extend(point);

                dirn.loadFromWaypoints(points[i], {getPolyline:true});
        }
        map.setZoom(map.getBoundsZoomLevel(bounds));
        map.setCenter(bounds.getCenter());
}
someFunctionToReplaceGEventLoad();

And, inside that function:

for (var i=0; i< dirn.getNumGeocodes(); i++)
{
        var coords = dirn.getGeocode(i).Point.coordinates;
        var p = new GLatLng(parseFloat(coords[1]), parseFloat(coords[0]));
        var marker= createMarker(p);
        map.addOverlay(marker);
        gmarkers.push(marker);
        map.addOverlay(dirn.getPolyline());
        gpolys.push(dirn.getPolyline());
}

???

I've tried to do something like this but with no success... =(

On Oct 24, 8:19 pm, Rossko <[EMAIL PROTECTED]> wrote:
> You perform a GXmlHttp to fetch some point co-ordinates.
> This will happen asynchronously; that means the data you have asked
> for will turn up later - much later in computer terms.
> Meantime, javascript execution continues ...
>
> Next you perform a
>     dirn.loadFromWaypoints(points, {getPolyline:true});
> where points is an array populated by the previous GXmlHttp section.
>
> Now, have a think; what will the contents of the points array be when
> you set up the loadFromWaypoints call?
> Hint : It is not yet 'later', the data has not come back yet from the
> GXmlHttp call.
>
> If the loadFromWaypoints relies on data from the GXmlHttp call, it
> MUST be placed within the GXmlHttp callback code.
>
> cheers, Ross K
--~--~---------~--~----~------------~-------~--~----~
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