Android Question Polygon calculation

Discussion in 'Android Questions' started by Duncan williamson, Mar 19, 2016.

  1. Duncan williamson

    Duncan williamson Member Licensed User

    Hi, im using googlemapextras and have a series of polygons which define property boundaries.
    I need to be able to calculate if a given lat/lng is within a specified distance of the edge of any part of the polygon..
    I have seen code posted which shows if a given lat/lng is within a polygon or outside but cannot see how to modify it to check distance... wondering if an expert can point me in the right direction

    regards
    Duncan
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Duncan H Williamson likes this.
  3. eurojam

    eurojam Well-Known Member Licensed User

  4. klaus

    klaus Expert Licensed User

    Attached you find a small project which returns if a point is inside the polygon, in the surrounding with a given distance or outsides the surrounding.
    It is an evolution of this project.
    The routine checks first if the point is in the polygon and then check if the distance of the point to the each polygon line is smaller than the given distance.
    The equations are general graphic equations not exactly for maps.
    But as Erel alrady pointed out: If the polygon is not too large then you can ignore the fact that the coordinates system is not Euclidean

    The red lines show the cursor.
    The yellow line shows the surrounding distance used (shown only on one side).

    upload_2016-3-21_13-12-20.png

    The coordinates of the polygon vertexes are saved in two arrays of Doubles.
    For lat/long coordinates you could calculate the distance like this.
    DistanceDegrees = DistanceKiloMeters / 6371 * 180 / cPi
    DistanceDegrees = DistanceMiles / 3959 * 180 / cPi
     

    Attached Files:

    Levit, somed3v3loper, Ohanian and 4 others like this.
  5. Duncan H Williamson

    Duncan H Williamson Member Licensed User

    Thank you Klaus
    I really appreciate all the expertise and help forwarded by everyone on this forum

    Regards

    Duncan
     
  6. wonder

    wonder Expert Licensed User

    This is AWESOME for game development!!! Thank you so much!!! :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice