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?
The Google Maps SDK for iOS now contains a feature called GMSGeometryContainsLocationthat will help you with a single line of code.
GMSGeometryContainsLocation
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
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.") }