This is simple bu,t is it possible?

28 views
Skip to first unread message

Esteve Graells

unread,
Oct 3, 2011, 1:15:05 PM10/3/11
to google-map...@googlegroups.com
We are a kid association for trekking outdoors. We'd like to offer dads the change to know when kids will arrive at the end of a route.

Using google maps api v3, we draw a polyline to show the route, let's say it's from a point A in the forest to point Z a bit far with waypoints around (B, C, D, E...). 

As one of our teachers is carrying a nexus one, we know, where they are and the speed they go (usually very very slow ;-) ).

Here is the question:

How can we know how long far is from the current position to the end of the route follwing our path route? Not straight direction (may be the mountain does not allow us), no driving.

So in fact it is quite simple: How to know distance from point X to Y following a custom route

I've checked the API, but couldn't find any function to do that.

Thanks in advance,
Esteve.

xelawho

unread,
Oct 3, 2011, 3:13:45 PM10/3/11
to Google Maps JavaScript API v3
> So in fact it is quite simple: *How to know distance from point X to Y
> following a custom route*.

I'd recommend having a look at the geometry library:
http://code.google.com/apis/maps/documentation/javascript/geometry.html

which has to be loaded explicitly, but works in conjunction with the
maps API

geoco...@gmail.com

unread,
Oct 3, 2011, 3:42:38 PM10/3/11
to Google Maps JavaScript API v3
On Oct 3, 10:15 am, Esteve Graells <esteve.grae...@gmail.com> wrote:
> We are a kid association for trekking outdoors. We'd like to offer dads the
> change to know when kids will arrive at the end of a route.
>
> Using google maps api v3, we draw a polyline to show the route, let's say
> it's from a point A in the forest to point Z a bit far with waypoints around
> (B, C, D, E...).
>
> As one of our teachers is carrying a nexus one, we know, where they are and
> the speed they go (usually very very slow ;-) ).
>
> Here is the question:
>
> *How can we know how long far is from the current position to the end of the
> route follwing our path route? Not straight direction (may be the mountain
> does not allow us), no driving.*
>
> So in fact it is quite simple: *How to know distance from point X to Y
> following a custom route*.

Actually it is a little more complicated than that. There is no
guarantee that the arbitrary point that you get from the nexus one is
on the polyline. So you first need to find the closest point on the
polyline to the position of the nexus one, then find the distance
along the polyline from that point to the end of the polyline.

All the pieces exist, you just need to put them together.

-- Larry

xelawho

unread,
Oct 3, 2011, 5:01:16 PM10/3/11
to Google Maps JavaScript API v3
mmm... but being that the idea of taking the GPS is to never stray too
far from the designated path, isn't all you need to do is get the
distance from the unit to the next waypoint - if it's off a couple of
metres, big deal?

or am I misunderstanding?

Rossko

unread,
Oct 4, 2011, 4:34:39 AM10/4/11
to Google Maps JavaScript API v3
You can't rely on the people being where they ought to be in the real
world, and the intervals between waypoints may be significantly large,
so that calculating nearest-point-on-line is a good idea in the
general case.
Reply all
Reply to author
Forward
0 new messages