Tengo una App en donde mando a poner localizaciones con sus respectivos Annotations. Logré cambiar la imagen del pin, pero veo que todas las imágenes son cambiadas.
Lo que me gustaría hacer es mostrar una imagen diferente por cada grupo de localizaciones, por ejemplo, tengo hospitales y farmacias, entonces me gustaría poner una cruz roja en Hospital y una medicina en farmacia.
Por ahora solo tengo las cruces y he estado investigando pero sigo sin éxito. Espero me puedan ayudar.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "identifier")
if annotationView == nil{
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
annotationView!.canShowCallout = true
annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
let pinImg = UIImage(named: "curz")
let size = CGSize(width: 50, height: 50)
UIGraphicsBeginImageContext(size)
pinImg!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annotationView!.image = resizedImage
}
else {
annotationView!.annotation = annotation
}
return annotationView
}