Created
April 12, 2017 01:08
-
-
Save ghecho/94b8bc50a0933c87ce069b1518dfea32 to your computer and use it in GitHub Desktop.
MapKit Polygon contains point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from http://stackoverflow.com/a/41923217 | |
extension MKPolygon { | |
func contain(coor: CLLocationCoordinate2D) -> Bool { | |
let polygonRenderer = MKPolygonRenderer(polygon: self) | |
let currentMapPoint: MKMapPoint = MKMapPointForCoordinate(coor) | |
let polygonViewPoint: CGPoint = polygonRenderer.point(for: currentMapPoint) | |
return polygonRenderer.path.contains(polygonViewPoint) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment