简体   繁体   English

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

[英]Indifferent behaviour of zoom level in IOS 6 mapview

I have been using the following code to zoom the mapview, so that all the annotations will be displayed in the view at the same time at optimum zoom level. 我一直在使用以下代码缩放地图视图,以便所有注释将以最佳缩放级别同时显示在视图中。 But in IOS 6, there seems to be some problem with the zoom level. 但在IOS 6中,缩放级别似乎存在一些问题。 Testing a few cases, I found that 1. If the contacts are in US, when the map is loaded it is zooming else where. 测试几个案例,我发现1.如果联系人在美国,当加载地图时,它会缩放到其他位置。 2. The zoom level seems to be correct in the UK area(as far as I have tested). 2.英国地区的缩放级别似乎是正确的(据我测试过)。 3. When I include contacts from both UK and US, the UK contacts gets rightly zoomed, but the US contacts are out of the view. 3.当我包括来自英国和美国的联系人时,英国的联系人会得到正确的缩放,但美国的联系人不在视线范围内。 But a slight swipe will ensure that all contacts fit into the view and are zoomed properly. 但轻微滑动将确保所有触点都适合视图并正确缩放。

-(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];
}

After loading the mapview with annotations, in random cases I get the following log 在使用注释加载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.)\""
)}

What could be the reason for this and how can I correct it? 可能是什么原因,我该如何纠正? Couldn't find anything helpful after googling. 谷歌搜索后找不到任何有用的东西。

I am not able to identify any particular pattern for this zooming inconsistency. 我无法识别这种缩放不一致的任何特定模式。 The above code is working fine in previous IOS versions. 以上代码在之前的IOS版本中运行良好。

I almost offered a bounty on your question but then I noticed, that with the new maps in iOS6 you just cannot zoom out to see the whole world (try it yourself in the maps app). 我几乎在你的问题上提供了赏金,但后来我注意到,使用iOS6中的新地图你无法缩小以查看整个世界(在地图应用程序中自己尝试)。 There is a maximum zoom level which you can figure out by commenting out your for loop and logging this: 有一个最大缩放级别,你可以通过注释你的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);

The output looks like this: 输出如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM