Reputation: 171
I have MKMarkerAnnotationView to change color of pins on my map.
func mapView(_ MapView:MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
But, when I start my app, marker of my defoult location changes to. How can I change pin without changing this marker? Code to view location is also simple
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
self.MapView.showsUserLocation = true
}
Thanks for answer! :)
Upvotes: 0
Views: 1146
Reputation: 7936
You could check if the annotation is the user location like this:
func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
Upvotes: 5
Reputation: 131398
In your method, check to see if the annotation object is an instance of MKUserLocation
. If it is, return nil to keep the standard user location annotation view.
(The Docs for mapView(_:viewFor:)
explain this.)
Upvotes: 0