javapolygongeofencingpoint-in-polygon

create polygon for a route using latitude and longitude


I am having a predefined route as a set of locations with latitude and longitude. I want to create a polygon by using these co-ordinates and want to know when the user deviates from it.

enter image description here

Anyone have any tips or sample code to draw a virtual fence across the points A, B and C ?


Solution

  • I don't know if polygon is the way to do it...

    I can suggest a more basic approach, where you compute the distance of point to a line segment and check for distance < fence radius

    you can compute line segments of your route, in your case the segments are (A,B) (B,C)

    when you got a new position and want to know if it reside within the fence, you just compute the distance of that position to each line segments

    the calculation of this is explained (very clearly, with code examples) in here

    the math of geo position is pretty straight forward when dealing with small areas (don't need to take the earth curvature into consideration) but even if you do, it's a small change and there a lot of code examples for that either