3

I developed a small application using MKMapView where MKAnnotations are added continuously on the map. It works well as long as the user does not touch the map view.

If the user tries to interact with the map, I noticed that no new MKAnnotationViews are added to the map. In fact, I discovered that as long as the user keeps interacting with the map, mapView: didAddAnnotationViews: is not called. As soon as the user's finger leaves the screen, mapView: didAddAnnotationViews: is called, passing in argument all the MKAnnotationViews that should have been added.

I tried forcing a call to mapView: didAddAnnotationViews, but I need to pass the MKAnnotationViews as arguments (so I can't used anything based on periodic calls), and when I try to call it at the end of mapView: viewForAnnotation:, it doesn't work since the view as not yet been added to the mapView. It is also a bad idea to try and add the annotation via another thread, since this will result in a Collection was mutated while being enumerated exception (probably coming from the mutable array storing the annotation views).

Is there any way to fix that ?

1 Answers1

0

You can create a custom class which implement delegate.

Than you can use MKAnnotationView's initWithAnnotation: method to create your annotations and add them in an array.

Then you can add them all to the map by using addAnnotations: method to add your annotations.

As long as you use custom annotations you need to manually create them, so user can't.

Ugur Kumru
  • 986
  • 6
  • 9
  • Thanks but this doesn't really answer my question. I cannot store all the annotations in an array since they come from a stream. –  Sep 13 '11 at 15:09