До сих пор я был в состоянии получить все аннотации, чтобы они стали маркерами, однако мне нужно было иметь отдельные маркеры для каждой аннотации / маркера.
Ранее я мог делать это, используя
// func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
//
// var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "AnnotationView")
// if annotationView == nil {
//
// annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView")
// }
//
// if annotation.title == "Speed Trap" {
// annotationView?.image = UIImage(named: "SpeedTrapImage.png")
// }else if annotation.title == "Traffic Accident" {
// annotationView?.image = UIImage(named: "AccidentImage.png")
// }else if annotation === mapView.userLocation {
// annotationView?.image = UIImage(named: "UserImage.png")
// }
// annotationView?.canShowCallout = true
// return annotationView!
// }
Вот код для моих маркеров в настоящее время
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = MKMarkerAnnotationView()
var identifier = ""
var color = UIColor.red
if let dequedView = mapView.dequeueReusableAnnotationView(
withIdentifier: identifier)
as? MKMarkerAnnotationView {
annotationView = dequedView
} else{
annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}
annotationView.markerTintColor = color
annotationView.glyphImage = UIImage(named: "pizza")
annotationView.glyphTintColor = .yellow
annotationView.clusteringIdentifier = identifier
return annotationView
}
Любая помощь в реализации этого будет принята с благодарностью