Reputation: 41
I'm trying to change my pins color, but when I'm adding the code to switch annotation it also changes my location icon (from blue dot to a pin). Any tips how to restore default user location icon?
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
switch annotation.title!! {
case "Ślęża":
annotationView.markerTintColor = UIColor(red: (69.0/255), green: (95.0/255), blue: (170.0/255), alpha: 1.0)
case "Śnieżnik":
annotationView.markerTintColor = UIColor(red: (52.0/255), green: (114.0/255), blue: (1.0/255), alpha: 1.0)
case "test":
annotationView.markerTintColor = UIColor(red: (246.0/255), green: (233.0/255), blue: (212.0/255), alpha: 1.0)
case "Brooklyn Bridge":
annotationView.markerTintColor = UIColor(red: (146.0/255), green: (187.0/255), blue: (217.0/255), alpha: 1.0)
default:
annotationView.markerTintColor = UIColor.blue
}
return annotationView
}
Upvotes: 0
Views: 602
Reputation: 100503
Add a check to exclude it
guard !(annotation is MKUserLocation) else { return nil }
let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
Upvotes: 1