4

I need to change the centerOffset property of an AnnotationView when the zoomlevel changed. I don't want to remove and add the Annotations again.

So how can I access and update the AnnotationViews after zooming?

Any ideas on this?

Best Regards, Christian

cweinberger
  • 3,518
  • 1
  • 16
  • 31

1 Answers1

4

One solution would be to use these MKMapView methods :

- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect // iOS4.2+ only!

to retrieve visible Annotations, then use :

- (MKAnnotationView *)viewForAnnotation:(id<MKAnnotation>)annotation;

To get the corresponding view (should never return nil if first function does it job correctly)

Then I guess changing centerOffset should do the job, (plus maybe some -[UIView setNeedsDisplay/Layout] to force a redraw)

Changing centerOffset depending on zoomLevel sounds strange, but I guess you have your reasons :)

Vincent Guerci
  • 14,379
  • 4
  • 50
  • 56
  • Thanks for this. I've used the mapView.annotations property to get the annotations (<4.2 depl. target). For updating the annotations I needed to reassign the coordinate.. `setNeedsDisplay` etc didn't work: `CLLocationCoordinate2D foo = annotation.coordinate; [annotation setCoordinate:foo];` Reason for changing the offset during zoomlevel: we have a map overlay with 3d buildings on it and wanted to show the annotations on the roofs for visual experience. The client can provide an offset on backend-side. Because of the different size after zoom-in/out the offset needed to be recalculated. – cweinberger Apr 22 '11 at 18:42
  • ah I see, I knew there was a reason to this, thanks for feedback :) – Vincent Guerci Apr 22 '11 at 19:03