我一直在使用以下代码来缩放 map View ,以便所有注释将以最佳缩放级别同时显示在 View 中。但在iOS 6中,缩放级别似乎存在一些问题。测试了几个案例,我发现 1. 如果联系人在美国,则加载 map 时,它会缩放到其他地方。 2. 在英国地区,缩放级别似乎是正确的(据我测试)。 3. 当我包含来自英国和美国的联系人时,英国联系人会正确缩放,但美国联系人不在 View 中。但轻轻滑动即可确保所有联系人都适合 View 并正确缩放。
-(void)zoomToFitMapAnnotations:(MKMapView*)mapViews insideArray:(NSArray*)anAnnotationArray
{
if([mapViews.annotations count] == 0) return;
CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;
CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;
for(MKPointAnnotation* annotation in anAnnotationArray)
{
topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}
MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides
region = [mapViews regionThatFits:region];
[mapView setRegion:region animated:YES];
}
加载带有注释的 map View 后,在随机情况下我会得到以下日志
<GEOTileSource: 0x108f6470>: Error downloading tiles Server Error: Error Domain=GEOErrorDomain Code=-204 "The operation couldn’t be completed. (GEOErrorDomain error -204.)" UserInfo=0x18a5b9c0 {UnderlyingErrors=(
"Error Domain=GEOErrorDomain Code=-204 \"The operation couldn\U2019t be completed. (GEOErrorDomain error -204.)\""
)}
这可能是什么原因以及如何纠正?谷歌搜索后找不到任何有用的信息。
我无法识别这种缩放不一致的任何特定模式。上面的代码在以前的IOS版本中运行良好。
最佳答案
我差点就你的问题提供悬赏,但后来我注意到,使用 iOS6 中的新 map ,你无法缩小 map 来查看整个世界(在 map 应用程序中亲自尝试一下)。您可以通过注释 for
循环并记录以下内容来找出最大缩放级别:
NSLog(@"region.span.latitudeDelta = %f", region.span.latitudeDelta);
NSLog(@"longitudeDelta = %f", region.span.longitudeDelta);
[map setRegion:region animated:NO];
NSLog(@"region.span.latitudeDelta = %f", map.region.span.latitudeDelta);
NSLog(@"longitudeDelta = %f", map.region.span.longitudeDelta);
输出如下所示:
region.span.latitudeDelta = 179.283409
longitudeDelta = 360.000000
region.span.latitudeDelta = 76.269114
longitudeDelta = 98.437499
关于iphone - iOS 6 map View 中缩放级别的无关行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12724589/