Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether MKMapView visibleMapRect contains a Coordinate?

If I have a MKMapView and a CLLocationCoordinate2D how do you test whether the map's visible area contains the coordinate?

like image 953
eric Avatar asked Apr 26 '13 14:04

eric


1 Answers

The fastest way is to use the inbuilt Apple functions which will make this sort of thing super quick!

if(MKMapRectContainsPoint(mapView.visibleMapRect, MKMapPointForCoordinate(coordinate)))
{
    //Do stuff
}

Where coordinate is your CLLocation2D.

This will be much faster than working out coordinates with a bulk if statement. Reason is that Apple use a Quadtree and can do fast lookups for you.

like image 175
Lee Armstrong Avatar answered Oct 04 '22 11:10

Lee Armstrong