I want to be able to tell if tap is within a MKPolygon.
I have a MKPolygon:
CLLocationCoordinate2D points[4];
points[0] = CLLocationCoordinate2DMak
Here is Swift 4.2 updated version thanks to @Steve Stomp
extension MKPolygon {
func contain(coor: CLLocationCoordinate2D) -> Bool {
let polygonRenderer = MKPolygonRenderer(polygon: self)
let currentMapPoint: MKMapPoint = MKMapPoint(coor)
let polygonViewPoint: CGPoint = polygonRenderer.point(for: currentMapPoint)
if polygonRenderer.path == nil {
return false
}else{
return polygonRenderer.path.contains(polygonViewPoint)
}
}
}