问题
How can i check if a pin is in viewable region of the map (MKMapView)?
回答1:
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;
来源:https://stackoverflow.com/questions/2591494/iphone-development-is-pin-annotation-in-a-viewable-map-region