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
3 Answers
Reset to default 4Finally 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
Construct the equations of each line AB, BC, CD, DA like this
y - y1 = m(x - x1)
wherem=(x1-x2)/(y1 - y2)
where A(x1, y1) and B(x1, y2)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:
Insert the coordinates of your polygon
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
版权声明:本文标题:javascript - Formula to Check Latitude & Longitude is within Area without Google Maps Api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745385635a2656362.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论