Hi,

I'm new to the Maps API, and Javascript in general and I am having
some trouble with the GDownloadUrl function.

I am trying to load a linestring from a KML file and display this as
an overlay.  Pretty simple stuff, but I am getting some slightly
strange behaviour.  My code is below:

var points = [];
var polyline;

//Load KML file
GDownloadUrl("./kml/03_11_2008 5_54 pm.kml", function(data,
responseCode) {

//Parse the kml data
var xml = GXml.parse(data);

//Locate the linestring node and pull out the coordinates
var path = xml.documentElement.getElementsByTagName("LineString");
for(i=0;i< path[0].childNodes.length;i++)
        {
        var node = path[0].childNodes[i];
        if(node.nodeName =="coordinates")
                {
                var coords = node.textContent;
                var pathPoints = coords.replace(/^\s*/, 
'').replace(/\s*$/,'').split
(/\s+/);
                for(var i = 0; i < pathPoints.length; i++)
                        {
                        var dataPoints = pathPoints[i].split(',');
                        //Data is in the wrong order so need to swap lat\lon 
values
                        points.push(new 
GLatLng(parseFloat(dataPoints[1]),parseFloat
(dataPoints[0])));

                        }
                }
        }

polyline = new GPolyline(points, "#ff0000", 10);
map.addOverlay(polyline);
});

Now this code works perfectly however I want to be able to store the
polyline and add it at a later time.

If I move the line:  map.addOverlay(polyline);

outside the scope of the GDownloadUrl function definition my polyline
is not displayed.  Now I guess this kinda makes sense as the xml data
only exists inside the scope of the function, and all the arrays are
using references to data that is only valid inside that scope.

My question is how can I store that overlay for use at a later point.
I originally thought that declaring the overlay variable outside the
scope and instantiating it in the scope may be enough, but no such
luck.

Any Javascript/Maps gurus out there able to offer any advice?

Cheers,

Chris

--~--~---------~--~----~------------~-------~--~----~
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