Lukas
Lukas

Reputation: 1356

MKMapView - Get corner of region

I'm currently trying to get the South-West and North-East corner (long and lat of each one) of the currently displayed region. I'm using the following delegate to get notified about region changes:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;

I hope someone can help me!

Cheers, Lukas

Upvotes: 1

Views: 1539

Answers (1)

nevan king
nevan king

Reputation: 113747

The region will give you the center (latitude, longitude), latitudinal span (in degrees of latitude) and longitudinal span.

To find the latitude of the North West corner, add 1/2 the latitudeDelta to the latitude of the region's center. Repeat as necessary with the other 3 values, adding or subtracting as necessary.

CLLocationCoordinate2D northWest = CLLocationCoordinate2DMake(
    myRegion.center.latitude + myRegion.span.latitudeDelta / 2.0,
    myRegion.center.longitude - myRegion.span.longitudeDelta / 2.0)

(code untested, just from the top of my head).

Upvotes: 8

Related Questions