我正在使用 MKMapView 开发组件。地图应在注释点击时加倍放大。为此,我尝试减少两倍的地图区域跨度,但有时它工作不正常: 这里代码和平:
MKCoordinateSpan newSpan = mapView.region.span;
NSLog(@"old: %f, %f", newSpan.latitudeDelta, newSpan.longitudeDelta);
newSpan = MKCoordinateSpanMake(newSpan.latitudeDelta / 2.0, newSpan.longitudeDelta / 2.0);
NSLog(@"new: %f, %f", newSpan.latitudeDelta, newSpan.longitudeDelta);
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMake(centerCoordinate, newSpan)];
NSLog(@"!!!! (%f, %f) (%f, %f)", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta);
我采用当前跨度,减少它并传递给 regionThatFits。有时结果是:
old: 0.609257, 0.914612
new: 0.304629, 0.457306
!!!! (55.805472, 37.579371) (0.608178, 0.914612)
regionThatFits 双打跨度传递给它。所以视觉效果是视图注释的居中而不缩放。
有什么建议么?