Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

## Check out if GPS pos is on a Route

This is a discussion on Check out if GPS pos is on a Route within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hello there! First thank you for this great forum, i searched through it but couldn't find exactly what i am ...

1. Junior Member White Belt
Join Date
Nov 2005
Posts
7

## Check out if GPS pos is on a Route

Hello there!

First thank you for this great forum, i searched through it but couldn't find exactly what i am looking for.

I have a problem, i don't exactly know how to solve.
I have a route going from A to B.
I get an GPS coordinate.
How do i check if the GPS position is on the Route between A and B ?

Thank you for any suggestions !

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

The only way to know this is to draw a polygon around the route. The poligon has to be wider than the route because there could be traffic deviations.

3. Junior Member White Belt
Join Date
Nov 2005
Posts
7

## mhm

this sounds very difficult. I think i don't quite understand, how do i draw the polygon ? Am i able to move along the route, which is calculatet and displayed in Mappoint. Do i draw the polygon then in mappoint ?

Might there be any hope that in mappoint 2006 this would be better ?

4. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

Sorry that I was so unclear. First let mappoint calculate the route for the vehicle. Then you can draw a polygon around the route. For each point in the polygon you draw you have to save the coordinates. This you can do in a beforeClick event handler.

To actual see if each GPS position of the car is within the polygon has nothing to do with mappoint anymore. Your program has to calculate it. It can be done following way:

Reduce the polygon to a triangle by replacing 2 successive sides by 1 new side, then calculate if the residual riangle contains the point. If not then calculate on the next triangle etc...

Not very easy done but not a big problem tough.

5. ## Hey Wil

Hey Wil

I'm not getting what you mean too... do you have a bit of code or pseudo code that gives us a better idea... It seems your solution is brilliant but I'm not sure the majority of us are understanding it.

Ciao,

6. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

I guess you right. If I read my explanation then I dont understeand eahter

This it is difficult because I dont know all the naming of figures etc. I try to make some drawings to explain what I mean, because even with some pseudocode it will be difficult, and it is really not so difficult, I have done sutch things several times.

I'll keep in touch

7. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

Whell I made a little drawing to explain what I mean. See http://www.mestdagh.biz/mp/polygon.gif

The top drawing is the polygon where the vehicle is maybe in or maybe not. How to check this simple. See second drawing.

we connect 2 sides (starting at random place), eg the red one, and by connecting we only have a triangle. Since we have not a matematical figure it is mutch more simple to calculate if vehicle is in it or not. If it is not in then we connect next point, the green one, if not in then the blue, etc...

if we are at the end then we have red alert: vehicle is not where it should be.

Is this more clear ?

Maybe this is stuff for a little article, but then better explaned and with some code samples

8. HI Wil

Sorry I missed your response on this item. Must of slipped through somehow.

It appears the link to the gif file is no longer available?

So Yes likey more clear - but No I didn't get a chance to look at it...

Thanks,
Ciao,

9. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

The link is still valid, it works here. It redirect to this: http://users.pandora.be/sonal.nv/mp/polygon.gif

10. Another approach to point-in-polygon calculations is outlined in Sedgwick's "Algorithms" (I see this is now a multi-volume work: I only have the 1 volume edition).

Basically, you project a 'ray' from your point to inifinity. Count the number of times it crosses the polygon edge. If this is odd, then the point must be in the polygon. If it is even, then the point must be outside the polygon.
I've implemented it for cartesian coordinates, and the maths becomes pretty simple if your ray is parallel to one of the axes.

Richard

Page 1 of 2 12 Last