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);
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?
Looks like those points are already "snapped" to the nearest road.
If you write the code inside the GDirections "load" event handler, you
shouldn't have any problem with the asynchronous nature of the call.
You can do them all in a single call to loadFromWaypoints, just pass
the array of points in and then to retrieve them use
GDirections.getGeocode(i).Point.coordinates (returns array lng, lat,
alt).
-- Larry
Those points are already snapped because I picked them from some
streets.
My purpose is to receive GPS coordinates from a moving car and to snap
them. Those come a little off-street and need snapping.
Now, about your second part, I'm not following.
You're saying I should do something like:
var dirn = new GDirections(map);
dirn.load(function(){
//function here
> Looks like those points are already "snapped" to the nearest road.
> If you write the code inside the GDirections "load" event handler, you
> shouldn't have any problem with the asynchronous nature of the call.
> You can do them all in a single call to loadFromWaypoints, just pass
> the array of points in and then to retrieve them use
> GDirections.getGeocode(i).Point.coordinates (returns array lng, lat,
> alt).
> -- Larry
> Those points are already snapped because I picked them from some
> streets.
> My purpose is to receive GPS coordinates from a moving car and to snap
> them. Those come a little off-street and need snapping.
> Now, about your second part, I'm not following.
> You're saying I should do something like:
> var dirn = new GDirections(map);
> dirn.load(function(){
> //function here
> > Looks like those points are already "snapped" to the nearest road.
> > If you write the code inside the GDirections "load" event handler, you
> > shouldn't have any problem with the asynchronous nature of the call.
> > You can do them all in a single call to loadFromWaypoints, just pass
> > the array of points in and then to retrieve them use
> > GDirections.getGeocode(i).Point.coordinates (returns array lng, lat,
> > alt).
> > -- Larry- Hide quoted text -
Thanks man! It was exactly what I was trying to do! The distance isn't
working, but I'll try to work that out, after I gather the points from
the XML.
I hope I won't have problems with that!
Many many thanks! =)
On Oct 6, 6:46 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
I've realized something now... I want to see more than one route.
Imagine I want to know the path of 2 cars.
As you made in your example, the paths get mixed. Is there anyway to
stop the polyline when one path ends and then, one the other path
starts the polyline draws another line?
Thanks!
On Oct 6, 6:58 pm, Mini0n <jfvolive...@gmail.com> wrote:
> Thanks man! It was exactly what I was trying to do! The distance isn't
> working, but I'll try to work that out, after I gather the points from
> theXML.
> I hope I won't have problems with that!
> Many many thanks! =)
> On Oct 6, 6:46 pm, "geocode...@gmail.com" <geocode...@gmail.com>
> wrote:
On Oct 7, 9:51 am, Mini0n <jfvolive...@gmail.com> wrote:
> Hi there, again! xD
> I've realized something now... I want to see more than one route.
> Imagine I want to know the path of 2 cars.
> As you made in your example, the paths get mixed. Is there anyway to
> stop the polyline when one path ends and then, one the other path
> starts the polyline draws another line?
Yes. Do a separate call to GDirections (with a separate array of
points) would be one...
> On Oct 6, 6:58 pm, Mini0n <jfvolive...@gmail.com> wrote:
> > OMG!
> > You rule!
> > Thanks man! It was exactly what I was trying to do! The distance isn't
> > working, but I'll try to work that out, after I gather the points from
> > theXML.
> > I hope I won't have problems with that!
> > Many many thanks! =)
> > On Oct 6, 6:46 pm, "geocode...@gmail.com" <geocode...@gmail.com>
> > wrote:
I'm trying to get those damn polylines, but got some issues...
I have successfully gather the info from the .xml, but the polylines
won't appear.
Locally it began giving the "a is undefined" error.
I've uploaded the code to http://gmapstest.awardspace.com/ but it
might have some differences, as locally I have other things. I believe
I've made the correct changes, making both sites equal, except one is
dynamic (local) and the other is static (gmapstest).
> I'm trying to get those damn polylines, but got some issues...
> I have successfully gather the info from the .xml, but the polylines
> won't appear.
> Locally it began giving the "a is undefined" error.
> I've uploaded the code tohttp://gmapstest.awardspace.com/but it
> might have some differences, as locally I have other things. I believe
> I've made the correct changes, making both sites equal, except one is
> dynamic (local) and the other is static (gmapstest).
> Can you see something wrong?
It looks like you don't understand the asynchronous nature of
GXmlHttp.
You send a request for 1234.xml then before it has completed, you
reuse the request object to send a request for 5678.xml. You have to
wait for it to be finished before you reuse it.