I have a map view with a large quantity of annotations (3000+), when the user is zoomed to a reasonable level all is well and fast.
Although when the user zooms out and
I would suggest a couple of things. One, look at the method annotationsInMapRect:
. According to the docs, it says:
This method offers a fast way to retrieve the annotation objects in a particular portion of the map. This method is much faster than doing a linear search of the objects in the annotations property yourself.
Two, look at dequeueReusableAnnotationViewWithIdentifier:
. According to the docs again, it says:
For performance reasons, you should generally reuse MKAnnotationView objects in your map views. As annotation views move offscreen, the map view moves them to an internally managed reuse queue. As new annotations move onscreen, and your code is prompted to provide a corresponding annotation view, you should always attempt to dequeue an existing view before creating a new one. Dequeueing saves time and memory during performance critical operations such as scrolling.
Finally, a couple of thoughts. Instead of doing these changes every time the - (void)mapView:(MKMapView *)_mapView regionDidChangeAnimated:(BOOL)animated
method is called, how about doing it according to some other rule (such as after a timer gets fired [make sure to reset the timer every time this gets called])? Another thing to consider: how about grouping annotations together that are super close to each other? Let's say you're zoomed out to where Rhode Island looks super small, maybe just a dozen pixels wide, and you have 100 points in Rhode Island -- you should just display one pin.
Hope this helps!