In order to setup a query to an external server I want to get the bounds of the current Map View in an iPhone app I\'m building. UIView should respond to bounds but it seems
this website solve the problem. http://www.softwarepassion.com/how-to-get-geographic-coordinates-of-the-visible-mkmapview-area-in-ios/
MKMapRect mRect = self.mapView.visibleMapRect;
-(CLLocationCoordinate2D)getNECoordinate:(MKMapRect)mRect{
return [self getCoordinateFromMapRectanglePoint:MKMapRectGetMaxX(mRect) y:mRect.origin.y];
}
-(CLLocationCoordinate2D)getNWCoordinate:(MKMapRect)mRect{
return [self getCoordinateFromMapRectanglePoint:MKMapRectGetMinX(mRect) y:mRect.origin.y];
}
-(CLLocationCoordinate2D)getSECoordinate:(MKMapRect)mRect{
return [self getCoordinateFromMapRectanglePoint:MKMapRectGetMaxX(mRect) y:MKMapRectGetMaxY(mRect)];
}
-(CLLocationCoordinate2D)getSWCoordinate:(MKMapRect)mRect{
return [self getCoordinateFromMapRectanglePoint:mRect.origin.x y:MKMapRectGetMaxY(mRect)];
}
-(CLLocationCoordinate2D)getCoordinateFromMapRectanglePoint:(double)x y:(double)y{
MKMapPoint swMapPoint = MKMapPointMake(x, y);
return MKCoordinateForMapPoint(swMapPoint);
}
-(NSArray *)getBoundingBox:(MKMapRect)mRect{
CLLocationCoordinate2D bottomLeft = [self getSWCoordinate:mRect];
CLLocationCoordinate2D topRight = [self getNECoordinate:mRect];
return @[[NSNumber numberWithDouble:bottomLeft.latitude ],
[NSNumber numberWithDouble:bottomLeft.longitude],
[NSNumber numberWithDouble:topRight.latitude],
[NSNumber numberWithDouble:topRight.longitude]];
}