Reputation: 31
Im setting a custom image for the user location on a map like this:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isEqual(mapView.userLocation) {
let identifier = "User"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if annotationView == nil{
annotationView = CustomPointAnnotation(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
annotationView!.image = UIImage(named: userImage)
return annotationView
}
return nil
}
Ive change the image property, how can I tell the map to update the MKAnnotationView?
Upvotes: 3
Views: 1627
Reputation: 490
One of my answers - https://stackoverflow.com/a/57868438/7505665
I had similar problem and solution in my case was this code
self.mapView.showsUserLocation = false
self.mapView.showsUserLocation = true
Upvotes: 1
Reputation: 11
This solutions works for me:
let userLocation = mapView.view(for: mapView.userLocation)
userLocation?.image = UIImage(named: "newImage")
userLocation?.isHidden = true
userLocation?.isHidden = false
Upvotes: 1
Reputation: 3561
I think you want to remove the annotations and then re-add them and that will force the map to update. Editing an existing annotation directly doesn't force the map to redraw.
Upvotes: 0