admin管理员组

文章数量:1425848

I have this Example Map:

I make Boundary Polygon shape,

-6.875165174925262, 107.56293296813965
-6.882663904407988, 107.66730308532715
-6.980818117491586, 107.67210960388184
-6.97093546084682, 107.54508018493652

How can I check if the given (Lat, Lng) -6.935884,107.611592 is inside that Boundary Polygon?

I need to do it without Google Maps API, because the program will be offline and must check more often than Google API's free service will allow.

Is there any geometric formula I can use for this? With PHP or Python if possible.

I have this Example Map:

I make Boundary Polygon shape,

-6.875165174925262, 107.56293296813965
-6.882663904407988, 107.66730308532715
-6.980818117491586, 107.67210960388184
-6.97093546084682, 107.54508018493652

How can I check if the given (Lat, Lng) -6.935884,107.611592 is inside that Boundary Polygon?

I need to do it without Google Maps API, because the program will be offline and must check more often than Google API's free service will allow.

Is there any geometric formula I can use for this? With PHP or Python if possible.

Share Improve this question edited Mar 11, 2014 at 3:52 AndyG 41.3k8 gold badges120 silver badges152 bronze badges asked Mar 5, 2014 at 8:33 haidarvmhaidarvm 6308 silver badges17 bronze badges 2
  • What have you already tried ? – kcak11 Commented Mar 5, 2014 at 8:34
  • I did try it with Google API , and i want it offline – haidarvm Commented Mar 5, 2014 at 8:35
Add a ment  | 

3 Answers 3

Reset to default 4

Finally i got the answer ... Detect Point in Polygon

this function help me alot ... and works great... others function sometime give false result whether point in or outside polygon

I'm not a javascript guy but, seems like a plane geometry from the schools, let say you have polygon with corners

A(x1, y1), B(x2, y2), C(x3, y3), D(x4, y4)

and if you want to check if a point E(X,Y) resides on the area of polygon you can do it like this

  1. Construct the equations of each line AB, BC, CD, DA like this y - y1 = m(x - x1) where m=(x1-x2)/(y1 - y2) where A(x1, y1) and B(x1, y2)

  2. Check if the point E(X, Y) resides on the corresponding side of the line like this

if (Y > m(X - x1) + y1)
{
   // resides on the upper area
}
else (Y < m(X - x1) + y1)
{
   // resides on the below area
}
else
{
   // resides right on the line
}

You can try to use this PHP library (https://github./xopbatgh/sb-polygon-pointer) for you case.

All you need to do is:

  1. Insert the coordinates of your polygon

  2. Ask the library is the any point with lat/lng inside this polygon

$polygonBox = [
    [55.761515, 37.600375],
    [55.759428, 37.651156],
    [55.737112, 37.649566],
    [55.737649, 37.597301],
];

$sbPolygonEngine = new sbPolygonEngine($polygonBox);

$isCrosses = $sbPolygonEngine->isCrossesWith(55.746768, 37.625605);

// $isCrosses is boolean

本文标签: javascriptFormula to Check Latitude amp Longitude is within Area without Google Maps ApiStack Overflow