How to detect that a point is inside a Polygon using Google Maps SDK for iOS?

百般思念 提交于 2019-12-07 06:32:01

问题


With the Googlemaps SDK for iOS, is it possible to detect that a point is inside a Polygon?

I found containsLocation() function in Google Maps JavaScript API, however, I couldn't find the same one in the iOS SDK.

Do you know any other ways?


回答1:


The Google Maps SDK for iOS now contains a function called GMSGeometryContainsLocation, which will help you out with a single line of code.

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

Source: Google Maps for iOS - Reference - GMSGeometryUtils




回答2:


Converting Rachid's answer to swift was trivial:

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


来源:https://stackoverflow.com/questions/19587792/how-to-detect-that-a-point-is-inside-a-polygon-using-google-maps-sdk-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!