How to determine if a point is inside a polygon using the Google Maps SDK for iOS?

With the Google Maps SDK for iOS, is it possible to detect that a point is inside a polygon?

I found containsLocation () in the Google Maps JavaScript API, however I could not find the same in the iOS SDK.

Do you know any other ways?

+4
source share
2 answers

The Google Maps SDK for iOS now contains a feature called GMSGeometryContainsLocationthat will help you 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 - Link - GMSGeometryUtils

+12
source

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.")
}
0
source

All Articles