【问题标题】:Indifferent behaviour of zoom level in IOS 6 mapviewIOS 6 mapview中缩放级别的无关行为
【发布时间】:2012-09-25 07:56:52
【问题描述】:

我一直在使用以下代码来缩放地图视图,以便所有注释将同时以最佳缩放级别显示在视图中。但在 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];
}

在加载带有注释的地图视图后,在随机情况下,我会得到以下日志

<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版本中运行良好。

【问题讨论】:

    标签: iphone ios6 ios6-maps


    【解决方案1】:

    我几乎对你的问题提出了赏金,但后来我注意到,使用 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);
    

    输出如下:

    region.span.latitudeDelta = 179.283409
    longitudeDelta = 360.000000
    region.span.latitudeDelta = 76.269114
    longitudeDelta = 98.437499
    

    【讨论】:

    • 这是一个概念性问题。例如,您可以尝试显示对用户最重要的最多位置。这实际上取决于您的用例。您可能还想依靠谷歌静态地图或向您的应用程序添加另一个地图服务。这取决于你。
    • 看来您不能不违反 Google 地图服务条款。看到这个问题:stackoverflow.com/questions/11448858/google-maps-in-ios6
    猜你喜欢
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 2011-07-21
    • 2011-07-15
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多