Iam doing a project for deliver food online through map. so the user should know the cook location. When the user tap on the annotation, it should view the food menus of the cook. so when user tap i need to call the cooks id. I can can call the cooks id according to the tag value.
**Juntos.swift**
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) ->
MKAnnotationView?
{
var annotationView =
mapView.dequeueReusableAnnotationView(withIdentifier: "identifier")
if annotationView == nil
{
annotationView = MKAnnotationView(annotation: annotation,
reuseIdentifier: "identifier")
annotationView!.canShowCallout = true
}
else
{
annotationView?.annotation = annotation
}
guard !(annotation is MKUserLocation) else
{
return nil
}
if iamA == "COOK"
{
annotationView!.image = UIImage(named: "foodie")
}
else
{
annotationView!.image = UIImage(named: "cook")
}
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
{
// how can i get annotation tag here
}
subclass MKAnnoation and enable it to hold custom data... e.g. the id:
class MyAnnotation: MKAnnotation {
var identifier: String!
}
now add that instead of MKAnnotation
let a = MyAnnotation()
....
a.identifier = "id525325"
mapView.addAnnotation(a)
and in then later use it
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let a = view.annoation as? MyAnnoation else {
return
}
let identifier = a.identifier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With