Tutorial :iPhone Development - Is Pin Annotation in a viewable Map Region


How can i check if a pin is in viewable region of the map (MKMapView)?


A pin is a MKPinAnnotationView, it extends from MKAnnotationView and has a property annotation (that conforms to the protocol MKAnnotation). Such annotation has itself another property coordinate.

Just compare the latitude / longitude of such coordinate to the region of your map.

something like this should do it :

  double minLong = myMap.region.center.longitude - myMap.region.span.longitudeDelta/2.0;  double maxLong = myMap.region.center.longitude + myMap.region.span.longitudeDelta/2.0;  double minLat = myMap.region.center.latitude - myMap.region.span.latitudeDelta/2.0;  double maxLat = myMap.region.center.latitude + myMap.region.span.latitudeDelta/2.0;

BOOL isPinInRegion = myPinCoordinates.longitude>=minLong && myPinCoordinates.longitude<=maxLong && myPinCoordinates.latitude>=minLat && myPinCoordinates.latitude<=maxLat;

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »