我有一个以特定位置为中心的启动应用程序。
//Calculate and set new center point
CLLocationCoordinate2D zoomLocation = CLLocationCoordinate2DMake(<some lat>,<some long>);
MKCoordinateSpan span;
span.latitudeDelta = 0.08;
span.longitudeDelta = 0.08;
//MKCoordinateRegion region = MKCoordinateRegionMake(zoomLocation, span);
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMake(zoomLocation, span)];
[mapView setRegion:region animated:YES];
[self refreshMap];
对 refreshMap 的调用会尝试计算地图的边界框,以便我可以在数据库中查询相应的信息。
//Calculate map's bounding box
MKMapRect mapRect = [mapView visibleMapRect];
MKMapPoint cornerPointNE = MKMapPointMake(MKMapRectGetMaxX(mapRect), mapRect.origin.y);
CLLocationCoordinate2D upperLeft = MKCoordinateForMapPoint(cornerPointNE);
MKMapPoint cornerPointSW = MKMapPointMake(mapRect.origin.x, MKMapRectGetMaxY(mapRect));
CLLocationCoordinate2D lowerRight = MKCoordinateForMapPoint(cornerPointSW);
if( fabs(upperLeft.longitude) > 80.00 || fabs(lowerRight.longitude) > 80.0) {
return;
}
我看到的问题是,在 iOS 6 中,在应用程序启动时未正确计算 lowerRight 坐标,并且由于 lowerRight.longitude > 80.0,地图数据不会刷新。正确计算了左上角。
在应用程序完成加载后,如果我平移地图,即使是最轻微的边界框计算也是正确的。
此代码在 iOS 5 中运行良好。
除了 mapView:regionDidChangeAnimated 之外,还有其他回调可以使用吗?refreshMap 的其余部分相当密集,我不想影响平移性能。
TIA
更新
我似乎找到了解决办法。而不是这样做
[mapView setRegion:region animated:YES];
我把 YES 改成了 NO
[mapView setRegion:region animated:NO];
现在在应用程序启动时正确计算了下角。