每当用户放大或缩小地图时,我都需要知道地图上当前表示了多少米(宽度或高度).
我需要的是MKCoordinateRegionMakeWithDistance的反函数来计算当前地图范围所代表的距离.
我尝试了以下代码但是我得到了错误的结果:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKMapRect mRect = self.map.visibleMapRect;
MKMapPoint northMapPoint = MKMapPointMake(MKMapRectGetMidX(mRect), MKMapRectGetMinY(mRect));
MKMapPoint southMapPoint = MKMapPointMake(MKMapRectGetMidX(mRect), MKMapRectGetMaxY(mRect));
self.currentDist = MKMetersBetweenMapPoints(northMapPoint, southMapPoint);
}
Run Code Online (Sandbox Code Playgroud)
如果我将地图区域设置为1500米,那么我得到1800这样的结果.
谢谢你的帮助,文森特