I want to update the images of some of my annotations on a mapview every 5 seconds, however I dont\' want to remove and re-add them to the map as this causes them to \'flash\' o
Swift version of Anna answer:
annotation.customImage = ... //the new image
let av = self.mapView.viewForAnnotation(dnwl!)
av?.image = annotation.customImage
In the case where the annotation is not nil, instead of adding and removing, try this:
annotation.customImage = ... //the new image
MKAnnotationView *av = [self.mapView viewForAnnotation:annotation];
av.image = annotation.customImage;
It seems you are using your own custom views for the annotations, in that case you can simply add a "refresh" method to your custom view and call it after you have updated the underlying annotation (ie: a custom view -a derived class from MKAnnotationView- is always attached to a potentially custom "annotation" class that conforms to the MKAnnotation protocol)
*) CustomAnnotationView.h
@interface CustomAnnotationView : MKAnnotationView
{
...
}
...
//tell the view to re-read the annotation data it is attached to
- (void)refresh;
*) CustomAnnotationView.m
//override super class method
- (void)setAnnotation:(id <MKAnnotation>)annotation
{
[super setAnnotation:annotation];
...
[self refresh];
}
- (void)refresh
{
...
[self setNeedsDisplay]; //if necessary
}
*) Where you handle the MKMapView and its annotations
for(CustomAnnotation *annotation in [m_MapView annotations])
{
CustomAnnotationView *annotationView = [m_MapView viewForAnnotation:annotation];
[annotationView refresh];
}