Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load annotations for visible region in MKMapView

I have about 400 MKAnnotationView´s that loads simultaneously into the MKMapView.

I understand that this isn't any good, it is a little bit slow, and I want to do it the "correct" way.

I zoom my map by a center coordinate:

MKCoordinateSpan span;
span.latitudeDelta = 0.8;
span.longitudeDelta = 0.8;

MKCoordinateRegion region;
region.span = span;

region.center = self.selectedCounty.coordinate;

[mapView setRegion:region animated:TRUE]; 

I only want to load the annotations that could be visible in that region.

I have a custom MKAnnotation called simply "Annotation" with a CLLocationCoordinate2D- and title-property.

I simply want to load the annotation for the "visible area" on the MKMapView so not all the annotation loads at the same time. And when the "visible area" on the MKMapView changes, I of course want to load annotations for that area.

I know that MKMapView has a delegate method which runs when the region changes.

But how do I know what annotations I should load for that region?

like image 535
Fernando Redondo Avatar asked Nov 08 '10 17:11

Fernando Redondo


1 Answers

MKMapRect visibleMapRect = mapView.visibleMapRect;
NSSet *visibleAnnotations = [mapView annotationsInMapRect:visibleMapRect];
like image 92
Shmidt Avatar answered Oct 07 '22 13:10

Shmidt