检查一个 GMSPolygon 是否在另一个 GMSPolygon 内部。

3
我有许多GMSPolygon在我的谷歌地图上。现在我想检查一个特定的多边形是否完全在其他多边形内部,同时需要找出哪些其他多边形与该多边形的边界相交,并且其他既不相交也不在给定的多边形内部,也不覆盖该多边形的多边形。
有人知道如何做到这一点吗?
编辑:
我得到了用于MKPolygon的库/代码来完成同样的事情,您可以在此处查看:https://github.com/geeksweep/MKPolygon-GSPolygonIntersections 现在,我在考虑将整个GMSPolygon转换为MKPolygon,并应用此库的代码以获得所需的结果。但是我认为这不是正确的方法。有没有任何简单的方法来做到这一点。
2个回答

3

在搜索了很多东西之后,我找到了一个解决方案,我认为这不太合适,但仍然比我发现的其他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
}

0

很抱歉,但我需要iOS的解决方案(请参见此处的“GMSPolygon”,还有“iOS”标签)。因此,上述库不适合我。 - Mehul Thakkar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接