IOS 6 mapview中缩放级别的无差异行为

Xav*_*ero 5 iphone ios6 ios6-maps

我一直在使用以下代码缩放地图视图,以便所有注释将以最佳缩放级别同时显示在视图中.但在IOS 6中,缩放级别似乎存在一些问题.测试几个案例,我发现1.如果联系人在美国,当加载地图时,它会缩放到其他位置.2.英国地区的缩放级别似乎是正确的(据我测试过).3.当我包括来自英国和美国的联系人时,英国的联系人会得到正确的缩放,但美国的联系人不在视线范围内.但轻微滑动将确保所有触点都适合视图并正确缩放.

-(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];
}
Run Code Online (Sandbox Code Playgroud)

在使用注释加载mapview后,在随机的情况下,我得到以下日志

<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.)\""
)}
Run Code Online (Sandbox Code Playgroud)

可能是什么原因,我该如何纠正?谷歌搜索后找不到任何有用的东西.

我无法识别这种缩放不一致的任何特定模式.以上代码在之前的IOS版本中运行良好.

bor*_*kur 2

我差点就你的问题提供悬赏,但后来我注意到,使用 iOS6 中的新地图,你无法缩小地图来查看整个世界(在地图应用程序中亲自尝试一下)。您可以通过注释循环并记录以下内容来找出最大缩放级别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);
Run Code Online (Sandbox Code Playgroud)

输出如下所示:

region.span.latitudeDelta = 179.283409
longitudeDelta = 360.000000
region.span.latitudeDelta = 76.269114
longitudeDelta = 98.437499
Run Code Online (Sandbox Code Playgroud)