我有一个应用程序,在启动中心位于特定位置。
//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是&gt; 80.0。 upperLeft正确计算。
应用程序完成加载后如果我平移地图,即使最轻微的边界框计算也是正确的。
此代码在iOS 5中运行良好。
我可以使用mapView:regionDidChangeAnimated以外的回调吗?其余的refreshMap相当密集,我不想影响平移性能。
TIA
更新
我似乎找到了解决办法。而不是这样做
[mapView setRegion:region animated:YES];
我将YES改为NO
[mapView setRegion:region animated:NO];
现在在应用启动时正确计算了下角。
答案 0 :(得分:1)
您是否使用MKMapRectOffset或Inset稍微移动可见的rect。
此外,我一直在重读你的问题而我可能错了;但是,我认为NE角是右上角,SW角是左下角。而你想要NW和SE的角落。
我无法在Map Kit参考中确认mapRect的原点位于左上角。