|How to check if a point/address lies on a route?||Gautam Thakur||11/27/11 2:22 PM|
I have a set of latitude and longitude and I want to know if between
|Re: How to check if a point/address lies on a route?||yip cto||11/28/11 10:13 AM|
You can use the directions service to generate a route and then check
|Re: How to check if a point/address lies on a route?||Gautam Thakur||11/28/11 12:42 PM|
Thanks It worked. I also did the same after trying other things. got
the route and all the coordinates of polyline. then just used the
distance between two points function to get the minimal with a
On Nov 28, 1:13 pm, yip cto <cto...@googlemail.com> wrote:> > two end points, are there any of the other locationlie? Is it
> You can use the directions service to generate arouteand then check
|Re: [Google Maps API v2] Re: How to check if a point/address lies on a route?||winster jose||1/4/13 7:06 AM|
Good work! I've given my vote.
You may have come across a scenario what I am searching for. I have a list of points on map. I need to check which of these points lie on a route.
On Sun, Dec 30, 2012 at 8:54 PM, Jonathan Kraemer <jonatha...@gmail.com> wrote:
|Re: [Google Maps API v2] Re: How to check if a point/address lies on a route?||montelpz||1/4/13 7:51 AM|
If you can, please share with us your app.
Thanks in advance.
2013/1/4, winster <wtj...@gmail.com>:
|Re: [Google Maps API v2] Re: How to check if a point/address lies on a route?||Jonathan Kraemer||1/7/13 5:46 AM|
The problem of just checking the distance from the point to the route is that it will give a false positive in cases the point is actually after the end of the route or before the beginning, for instance.
What I did there is actually pure math.
See: the route is actually a bunch of lines. Using math you can get the equation of a line and using math functions, get the distance from a point to a line, plus check if the projection of a point lies inside the limits of the line. The tricky part is that in order to do all this calcs, we need the start/end point of the route lines and the points positions as a cartesian system, instead of latitude, longitude angles, X and Y dimensions in meters. That's not a problem actually, with a good enough approximation, we can convert lat,lon angles to X,Y distances. The result is not perfectly accurate, but it's proven that it is enough, I did not see cases of false positives in my app yet.
Knowing that, here is more or less how I solved this:
First of all, I am using the version 3 of the Google Maps API.
So first step I make a look through all the points at the array overview_path that the directions API returns. So I make this loop from position 0 to "length-1" because overview_path contains points and I want to read always the current point AND the next one, so I have a line.
But before calculating any information, I convert the coordinates to meters.
With that in hands, I get the line equation, which is pure math. And again using math, calculate the distance from each point to the line and also project the point to the line and check if it is inside the limits (the initial and final points I am considering).
Now that I know if the point is in the limits and the distance from the point to the line, I can check if it is close enough that I can consider that point "in" the route.
I am not sure if it is understandable for you guys, let me know and I will try to make it simpler, I can share the code with you guys or I can create a "service" so you can just load in your apps and use it, what do you think?
2013/1/4 Carlos Montelongo <mont...@gmail.com>
|Re: [Google Maps API v2] Re: How to check if a point/address lies on a route?||Jonathan Kraemer||1/7/13 5:47 AM|
Sorry, let me explain: I had to "project" the points to the line because we can't expect the point we want to check will be exactly in the line we are checking.
2013/1/7 Jonathan Kraemer <jonatha...@gmail.com>