I am trying to show thousands of potential pins (Annotations) to the user on the MKMapView. Does anyone know if the map is using occlusion culling to render only the visible annotations?
This is for iOS 7+ using xCode 6.4
I am trying to show thousands of potential pins (Annotations) to the user on the MKMapView. Does anyone know if the map is using occlusion culling to render only the visible annotations?
This is for iOS 7+ using xCode 6.4
Copyright © 2021 Jogjafile Inc.
When talking about managing large number of annotations, we should differentiate between "annotations" and "annotation views". When you add many annotations to a map view, the collection of those light-weight
MKAnnotation
objects remain in theannotations
array. But the map view offers a mechanism to mitigate the memory issues that can arise from a large number of associated "annotation views".When you add thousands of annotations to a map view, the only annotation views that are instantiated are those that are visible (and those that near the visible portion of the map. If you properly use
dequeueReusableAnnotationViewWithIdentifier
inviewForAnnotation
, as you scroll and annotations views fall out of view, when it needs new annotation views, it will recycle those that have scrolled out of view:Thus, this keeps the number of annotation views to some manageable number, not necessarily instantiating new annotation views until they're absolutely needed (i.e. there don't happen to be any old annotation views that have scrolled out of view, available for reuse).
If, however, the user zooms out on the map so there are an unmanageable number of annotation views visible simultaneously, you have to manage this situation yourself. Back in WWDC 2011, there was a video Visualizing Information Geographically with MapKit that demonstrates interesting model when dealing with tons of annotations. Specifically, they deal with the problem that you zoom out and there are so many annotation views that they start overlapping and become too numerous. This video demonstrates an approach in which you aggregate annotation views together as you scroll out (if necessary). The implementation is fairly rudimentary, but it illustrates the concept.