Is it possible to determine if a third point is on a route between two other points? (urban areas)

112 views
Skip to first unread message

Gil

unread,
Aug 19, 2010, 4:13:17 PM8/19/10
to Google Maps JavaScript API v3
Hi,
I would like to define two coordinates/datum points in the same
street. The question is whether after defining a third coordinate,
would I be able to know if it is between the first two coordinates (in
the same segment)?

I tried look for a function (something which contains (point, route))
and didn’t find one.
Another try I've made, and maybe is possible, is trying to check
whether the distance between a point and a polyline is zero. The only
problem is that I don't know if it will work when the street is curved
(because I need the line between the polyline points will be a curved
line according to the street and not a straight line between the
points).

Thanks For Your Help

Gil

Michael Short

unread,
Aug 20, 2010, 4:01:05 PM8/20/10
to google-map...@googlegroups.com
I would suggest creating a rectangle with the two furthest points and
then you could test the middle point with point-in-poly or PIP.

http://snippets.dzone.com/posts/show/5295

> --
> 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 google-map...@googlegroups.com.
> To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>


Sincerely,
--
Michael Short
(901) 233-9926

sgiddings

unread,
Aug 21, 2010, 3:16:46 AM8/21/10
to Google Maps JavaScript API v3
Michaels solution will only tell you if the point is between the two
original points.
It will not tell you if the third point is on a road.

The only way I can see you being able to do this accurately would be
to
1. call the directions service and ask for the route between the two
points
2. scan through the paths array inside each Directions step
3. You can then use a simple formula to see if the point falls on the
path as they are all straight lines.
> > For more options, visit this group athttp://groups.google.com/group/google-maps-js-api-v3?hl=en.

Gil

unread,
Aug 22, 2010, 3:45:36 AM8/22/10
to Google Maps JavaScript API v3
Hi,
Thanks for your help.
I think I have some lack in understanding the meaning of route.
If I have start point and end point in a curved street, and I'm
calling directions service, what will I get back ?
Few points in array that for one to another sketched a straight line?
Few straight segments in array that together creates curved line?

Thanks for your time
Gil

stu

unread,
Aug 22, 2010, 8:30:59 PM8/22/10
to Google Maps JavaScript API v3
Hi Gil
to do what you want to do you probably need to understand the
DirectionsResult well (which is what comes back from a
DirectionsService request, if status==OK).
re - meaning of Route
The API v3 reference, at DiectionsResult, and the Services document at
DirectionsResult are worth reading and re-reading! I'm trying to get
up to speed on this at the moment, and my understanding is that the
result is a JSON object consisting of the following:
* one or more Routes - a route is the full journey A-B, and there may
be more than one good way of getting from A to B
* each Route contains one or more DirectionsLeg objects
* each DirectionsLeg contains one or more DirectionsStep objects (and
each part of the text based directions instructions)

Step is essentially the lowest level, but each DirectionsStep contains
a path which is an array of latlng points that describe the straight
line segments that make up that step. When you make them visible on a
map (by for instance placing a marker at each latlng point in the
step), you can see how bends in a road are navigated with a series of
straight lines.
So at the bottom of it all, a windy wiggly route is just a bunch of
staight lines, - quite short ones for tight bends.

The following example was for me a great start to get an understanding
of rendering the DirectionsResult components - look at the source,
where he iterates through the legs and steps:
http://www.geocodezip.com/v3_directions_custom_iconsC.html

re your problem.
What sgiddings was saying then, is to go through all the straight line
segments that are in DirectionsStep, for each, you need to do a
calculation to see if your point lies on that line (or better, lies
close enough to a point on the line). I've seen examples of how to
do that, but right now can't remember where.
Hope thats useful
...stu

geoco...@gmail.com

unread,
Aug 22, 2010, 9:07:29 PM8/22/10
to Google Maps JavaScript API v3
Bill Chadwick has a function for v2:
http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm

The function actually has all kinds of information that it calculates
(or at least can know) like the vertices of the line segment that is
closest.

-- Larry
Reply all
Reply to author
Forward
0 new messages