I was wondering how to get all the information from a annotation in swift when tapped on. There is this article: Swift, How to get information from a custom annotation on clicked
But that doesn't answer my question. I made some modifications to the code.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if let annotationTitle = view.annotation?.title {
if let annotationPhone = view.annotation?.phoneNumber as? MKAnnotationView {
print("User tapped on annotation with title: \(annotationPhone!)")
}
print("User tapped on annotation with title: \(annotationTitle!)")
}
}
Creating the pin if this helps at all:
let annotation = MKPointAnnotation()
annotation.coordinate = item.placemark.coordinate
annotation.title = item.name
annotation.subtitle = "Coffee Shop"
self.map.addAnnotation(annotation)
But I get the error:
Value of type 'MKAnnotation' has no member 'phoneNumber'
What am I doing wrong?