检查纬度和公式的公式经度在没有Google Maps Api的区域内

时间:2014-03-05 08:33:29

标签: javascript php python

我有this示例地图:

enter image description here

我制作边界多边形,

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

如何检查给定的(Lat,Lng)-6.935884,107.611592是否在该边界多边形内?

我需要在没有Google Maps API的情况下执行此操作,因为该程序将处于脱机状态,并且必须经常检查,而不是Google API的免费服务。

我可以使用任何几何公式吗?如果可能,使用PHP或Python。

3 个答案:

答案 0 :(得分:2)

最后我得到了答案...... Detect Point in Polygon

这个功能帮我很多......而且效果很好...... 其他函数有时会给出错误的结果,无论是在多边形内部还是外部

答案 1 :(得分:1)

我不是一个javascript人,但是,看起来像学校的平面几何,假设你有角的多边形

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

enter image description here

如果你想检查点E(X,Y)是否位于多边形区域,你可以像这样做

  1. 构造每条线AB,BC,CD,DA的方程,如y - y1 = m(x - x1),其中m=(x1-x2)/(y1 - y2)其中A(x1,y1)和B(x1,y2)

  2. 检查点E(X,Y)是否位于该行的相应一侧

  3. 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
    }
    

答案 2 :(得分:0)

您可以尝试使用此PHP库(https://github.com/xopbatgh/sb-polygon-pointer)。

您需要做的是:

  1. 插入多边形的坐标

  2. 问该库是该多边形内包含经/纬度的任意点

$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

相关问题