简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM