I'd like to a-synchronically load images for my custom MKAnnotationView; I'm already using the EGOImageView-framework (it goes very well with UITableViews), but I fail to make it work on MKMapView. Images seem to be loaded, but I cannot refresh them on the map - [myMap setNeedsDisplay]
does nothing.
views:
1381answers:
3
A:
I haven't tried it myself, but it might work:
Get a view for annotation using MKMapView - (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation
method and set new image to it.
Edit: Tried to do that myself and this approach worked fine for me:
// Function where you got new image and want to set it to annotation view
for (MyAnnotationType* myAnnot in myAnnotationContainer){
MKAnnotationView* aView = [mapView viewForAnnotation: myAnnot];
aView.image = [UIImage imageNamed:@"myJustDownloadedImage.png"];
}
After calling this method all annotations images were updated.
Vladimir
2009-11-10 13:24:18
that's how it's done now. But this way image is loaded synchronically.
Konstantin
2009-11-10 13:28:09
And if you call it after the image is loaded and set this image to the view - doesn't it work?
Vladimir
2009-11-10 13:50:42
that's the question - how to set this image later. By doing so, image gets not updated on the MKAnnotationView
Konstantin
2009-11-11 14:09:19
As I've written - MKMapView allows you to obtain a view for any annotation. See in edited answer how it can be used.
Vladimir
2009-11-11 14:31:44
A:
I couldn't add a comment so i am usign the answer box -
What is the myAnnotationContainer in your code? is it the MKAnnotationViewContainer? How do you get that?
Dave
2010-03-25 23:25:57
A:
This is the only way I've found to force redraw of MKAnnotationViews:
// force update of map view (otherwise annotation views won't redraw)
CLLocationCoordinate2D center = mapView.centerCoordinate;
mapView.centerCoordinate = center;
Seems useless, but it works.
ZeroDiv
2010-04-12 04:40:02