I have POI's in Dictionary:
["_id": "12345ACB", "title": "Some Shop Place", "category": "Shop", "latitude": 12.345677, "longitude": 21.12348], ...
and I have function for adding annotations:
func addPlaces() {
for poi in pois {
let pin = MKPointAnnotation()
if let loc = poi["location"] as? NSDictionary {
pin.coordinate = CLLocationCoordinate2D(latitude: (loc["lat"] as? Double)!, longitude: (loc["lng"] as? Double)!)
}
if let cat = poi["_category"] as? NSDictionary {
pin.subtitle = cat["name"] as? String
}
pin.title = poi["title"] as? String
mapView.addAnnotation(pin)
}
}
and also a callout function:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
let info = view.annotation
let placeName = info?.title
let placeInfo = info?.subtitle
let ac = UIAlertController(title: placeName!, message: placeInfo!, preferredStyle: .actionSheet)
ac.addAction(UIAlertAction(title: "Open", style: .default, handler: { (UIAlertAction) in
// Here I need POI's _ID
self.performSegue(withIdentifier: "DealsSegue", sender: self)
}))
present(ac, animated: true)
}
So, in action for alert I need _id from POI's dictionary for specific (tapped) pin?
Thanks