2013-10-25 51 views
4

使用适用于iOS的Google Maps SDK,是否可以检测到点在Polygon内?如何使用Google Maps SDK for iOS检测点在Polygon内部?

我在Google Maps JavaScript API中发现了containsLocation()函数,但是我在iOS SDK中找不到相同的函数。

你知道其他方法吗?

+1

有在谷歌没有提供直接的方法映射IOS SDK。你可以通过使用基于[早期回答]中提出的算法的数学计算来发现点是否在多边形内部(http://stackoverflow.com/questions/19106556/get-location-address-wrt-the-polygon- i-am-in/19109375#19109375)。您可以在ios中使用相同的方法 –

+0

请提交[适用于iOS的Google地图SDK的功能请求](https://code.google.com/p/gmaps-api-issues/issues/entry?template=Maps %20SDK%20for%20iOS%20-%20Feature%20Request)。 – Brett

回答

12

适用于iOS的Google Maps SDK现在包含一个名为GMSGeometryContainsLocation的函数,它可以帮助您完成一行代码。

if (GMSGeometryContainsLocation(yourPoint, pathOfPolygon, YES)) { 
    NSLog(@"YES: you are in this polygon."); 
} else { 
    NSLog(@"You do not appear to be in this polygon."); 
} 

来源:Google Maps for iOS - Reference - GMSGeometryUtils

0

转换拉希德的回答SWIFT是微不足道:

if GMSGeometryContainsLocation(yourPoint, pathOfPolygon, true) { 
    print("YES: you are in this polygon.") 
} else { 
    print("You do not appear to be in this polygon.") 
} 
相关问题