Mustafa
Mustafa

Reputation: 20564

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)?

Upvotes: 0

Views: 1278

Answers (1)

yonel
yonel

Reputation: 7865

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;

Upvotes: 3

Related Questions