ios5gpsmapkituserlocationmkcoordinateregion

How do I determine if the current user location is inside of my MKCoordinateRegion?


I have a coordinate region that I have determined contains the limits of what I want to show for my app. I have set this up as an MKCoordinateRegion with center point lat, longitude and a span. How do I determine if the current userLocation is inside of my coordinate region?


Solution

  • Use map rects. Here's an example using the map's current visible rect. With regards to your question, you could use convertRegion:toRectToView: to first convert your region to a MKMapRect beforehand.

    MKMapPoint userPoint = MKMapPointForCoordinate(mapView.userLocation.location.coordinate);
    MKMapRect mapRect = mapView.visibleMapRect;
    BOOL inside = MKMapRectContainsPoint(mapRect, userPoint);