我在MKMapView上有一个缩放/缩小按钮。当用户处于最大缩放级别时,缩放正在工作,但缩放正在崩溃。我有例外:
'NSInvalidArgumentException', reason: 'Invalid Region <center:+37.17818069, -96.05458069 span:+237.74976671, +218.02936959>'
有时使用NaN值。如何检查下一个区域的有效性?
这是我的代码
MKCoordinateRegion region = self.mapView_apple.region;
region.span.latitudeDelta *= 2.0;
region.span.longitudeDelta *= 2.0;
self.mapView_apple.region = region;
所以根据Chan的评论,我的解决方案是:
MKCoordinateRegion region = self.mapView.region;
MKCoordinateSpan newSpan = region.span;
newSpan.latitudeDelta *= 2.0; // divide for zooming and change the value if you want
newSpan.longitudeDelta *= 2.0;
if(newSpan.latitudeDelta < 180.f && newSpan.longitudeDelta < 180.f) {
region.span = newSpan;
[self.mapView setRegion:region animated:YES];
}
谢谢!