iOS6 中的 MapView 在北纬 75 度>不会显示某些缩放级别



此代码设置以viewDidLoad中指定位置为中心的默认缩放级别。该代码在以前版本的iOS中运行良好:

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, visibleDistance, visibleDistance);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
.
.
.
[mapView setRegion:adjustedRegion animated:NO];

然而,在iOS6中,对于纬度高于~75(>75.1)的位置,应用程序崩溃,并显示以下消息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Invalid Region <center:nan, nan span:nan, nan>'

我发现对于给定的缩放级别,mapView无法在内部设置正确的MKCoordinateRegion[mapView regionThatFits:region]将所有值返回为nan。如果我直接使用region变量,它只显示默认映射(整个世界)。

经过一些测试,我发现通过调整visibleDistance,我可以使代码正常工作。神奇的距离似乎略高于20公里(对于一系列纬度和纬度德尔塔值来说,在22到23公里之间)。这种情况只发生在北纬度地区(-80很好)。

地图在初始定位后的任何位置都可以使用。看起来苹果改变了可见地图区域的初始化方式。我对受影响的区域使用更高的缩放级别作为解决方法。有没有其他方法可以让它正常工作?

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, visibleDistance, visibleDistance);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
.
.
.
[mapView setRegion:adjustedRegion animated:NO];

它会起作用的。。

CLLocationCoordinate2D southwest, northeast;
southwest.latitude = 34.172684;
southwest.longitude = -118.604794;
northeast.latitude = 34.236144;
northeast.longitude = -118.500938;
BSForwardGeocoderCoordinateBounds *bounds = [BSForwardGeocoderCoordinateBounds boundsWithSouthWest:southwest northEast:northeast];

试试这个。。。。

我的iPhone4S发生了故障,控制台显示了该地区的nan值。在尝试了SO的大约7种不同的解决方案和Apple DTS的各种建议后,我通过消除regionThatFits调用来解决了这个问题。我只是简单地使用:

CLLocationDistance visibleDistance = 100000; // 100 kilometers
MKCoordinateRegion adjustedRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, visibleDistance, visibleDistance);
[_mapView setRegion:adjustedRegion animated:YES];

显然,区域ThatFits方法存在问题。

我在一个中文网站上找到了这个代码的版本,它似乎对我有效。他只是在返回NAN时绕过sizeThatFits,因此只有在必要时才进行调整。如果苹果修复了这个错误(假设它是一个错误),那么它根本不会成为问题。

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coordinate, mapSizeMeters, mapSizeMeters);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
if (isnan(adjustedRegion.center.latitude)) {
// iOS 6 will result in nan. 2012-10-15
adjustedRegion.center.latitude = viewRegion.center.latitude;
adjustedRegion.center.longitude = viewRegion.center.longitude;
adjustedRegion.span.latitudeDelta = 0;
adjustedRegion.span.longitudeDelta = 0;
}

[mapView setRegion:adjustedRegion animated:YES];

最新更新