What event is fired when MKMAPVIEW extent changes

2019-03-22 07:42发布

问题:

What event is fired when the MKMAPVIEW changes extent (zooms in or out, panning)?

I need to get the coordinates that are used to display the map.

回答1:

You should adopt the MKMapViewDelegate protocol and implement mapView:regionDidChangeAnimated: method which will be called in the event the region changes. However since it will be called many times when scrolling you should take that into consideration before implementing that method.

Getting the Top-Left coordinate of the map

CLLocationCoordinate2D topLeftCoordinate = [self.mapView convertPoint:CGPointMake(0,0)
                                                 toCoordinateFromView:self.mapView];

Or

Since you know the region already,

MKCoordinateRegion region = self.mapView.region;
MKCoordinateSpan span = region.span;
CLLocationCoordinate2D center = region.center;

CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(center.latitude - span.latitudeDelta / 2, center.longitude - span.longitudeDelta / 2);
/* Similarly, get the others  */