How can i tag the annotation in the map and get the tag value while selecting the annotation

Viewed 2010

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
}
2 Answers
Related