I have the swift code below that draws a polygon and drops an annotation on MKMapView. I am trying to figure out how i could identify if the annotation\'s coordinate is with
Method to be attached to a gesture recognizer:
@objc
func mapTapped(_ tap: UILongPressGestureRecognizer) {
if tap.state == .recognized {
let touchPoint = tap.location(in: mapView)
let coord = mapView.convert(touchPoint, toCoordinateFrom: mapView)
for overlay: MKOverlay in mapView.overlays {
if let polygon = overlay as? MKPolygon {
let renderer = MKPolygonRenderer(polygon: polygon)
let mapPoint = MKMapPoint(coord)
let rendererPoint = renderer.point(for: mapPoint)
if renderer.path.contains(rendererPoint) {
// here comes your code
}
}
}
}
}