What event is fired when MKMAPVIEW extent changes

橙三吉。 提交于 2019-12-04 13:55:55

问题


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  */


来源:https://stackoverflow.com/questions/6426203/what-event-is-fired-when-mkmapview-extent-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!