I guess what you're looking for is :
- (NSSet *)annotationsInMapRect:(MKMapRect)mapRect
Quoting Apple documentation :
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.
Take care that's it's only Available in iOS 4.2 and later, I'm afraid there is no other solution than custom code in previous iOS versions.
EDIT About your comment : My guess is that for a few thousands annotation, the above method should do the trick, MKAnnotation
is a lightweight protocol, scanning an array by filtering on coordinate should be ok. But beware on not adding thousands of MKAnnotationView
, that works on an iPhone 4, already did it, but you almost can't scroll map :)
Then I would suggest :
- Use that method, quick to code, easy, then do some performance tests, on device
- If performances are not enough.... or you have to support prevous iOS versios, no magic, write you own code. (shouldn't be that hard, there are utility methods for converting regions and such)
About memory, hey, these devices have easily at least 64MB free memory for your app, and will kill some processes if not, don't be scared by a few K of annotations! Just take care of memory leaks, especially on such intensive processes.