I\'ve made a few annotations inside the Map and when I tap on them I see some informations and I have a button that opens Maps and with the right information that I can\'t take
For Swift 4
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
var selectedAnnotation = view.annotation
}
For that you can use selected Annotation
from didSelectAnnotationView
, then store that annotation to instance variable and after that used annotation in your Button
action method.
var selectedAnnotation: MKPointAnnotation?
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
self.selectedAnnotation = view.annotation as? MKPointAnnotation
}
func info(sender: UIButton) {
print(selectedAnnotation?.coordinate)
}
Edit: As of you have custom MKAnnotation
class you need to use that.
var selectedAnnotation: Islands?
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
self.selectedAnnotation = view.annotation as? Islands
}