检查 GMSPolygon 是否在其他 GMSPolygon 内部

Check whether GMSPolygon is inside other GMSPolygon or not

我的 google 地图中有许多 GMSPolygon。现在我想检查一个特定的多边形是否位于(完全位于)任何其他多边形内。还需要找出哪些其他多边形与该多边形的边界相交,以及其他既不相交、既不在给定多边形内部也不覆盖该多边形的多边形。

谁能知道如何做到这一点?

编辑:

我得到 library/code 来为 MKPolygon 做同样的事情,你可以在这里看到它:https://github.com/geeksweep/MKPolygon-GSPolygonIntersections

现在,我想我应该将整个 GMSPolygon 转换为 MKPolygon 并应用该库的代码以获得所需的结果。但我认为这不是这样做的正确方法。有没有人有任何想法以非常简单的方式做到这一点。

你可以使用这个库:

http://sourceforge.net/projects/polyclipping/

查看哪些其他多边形与您的多边形边界相交

在搜索了很多东西之后,我找到了一个解决方案,我认为这不太合适,但仍然比我找到的其他 3-4 个解决方案要好。如果有人找到更好的解决方案,请告诉我,如果我发现它们更好更合适,我会接受那个并且也会更改我的代码。现在,我使用以下代码来执行此操作。

GMSPath *path1=polygon1.path, *path2=polygon2.path;
BOOL flag1= NO;
BOOL flag2= NO;
for (int i=0; i<path1.count; i++)
{
    if (GMSGeometryContainsLocation([path1 coordinateAtIndex:i], path2, YES)==false)
    {
        flag1 = true;
    }

    if (GMSGeometryIsLocationOnPath([path1 coordinateAtIndex:i], path2, YES)==true)
    {
        flag2 = true;
    }
}

if (flag1==false)
{
    NSLog(@"polygon1 is fully inside polygon2");
}
else if (flag2 == true)
{
    NSLog(@"polygon1 intersects with polygon2");
}
else
{
    //Do the above procedure again just by switching path1 and path2
    //and at end you can find that is polygon2 is inside polygon1 or not, 
    //and if it is not, then this means both polygon1 and polygon2 are distinct
    //then neither intersects, nor inside each other
}