简体   繁体   English

MKMapView setRegion设置为小区域会导致卫星图像加载失败

[英]MKMapView setRegion to Small Area causes Failed Satellite Image Loading

I have been working on the same app for a number of months, and this is a new problem. 我已经在同一个应用程序上工作了几个月,这是一个新问题。 I am wondering if there has been a change in the server side of the Apple Map data. 我想知道苹果地图数据的服务器端是否发生了变化。 Here's the issue: 这是问题所在:

My app (at times) wants to set an MKMapView region to the most fully zoomed in value possible around a particular location. 我的应用程序(有时)希望将MKMapView区域设置为在特定位置附近尽可能最大的放大值。 To do this, I do something like: 为此,我要做类似的事情:

self.map.mapType = MKMapTypeHybrid;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(item.lat, item.lng), 1.0, 1.0);
[self.map setRegion:region animated:NO];

Regardless of where item's coordinate is, I get the gridded "no satellite images" background. 无论item's坐标在哪里,我都会得到网格化的“无卫星图像”背景。 This does not seem to be related to available satellite imagery, as it behaves consistently across many areas of the US. 这似乎与可用的卫星图像无关,因为它在美国许多地区都表现一致。

I am aware that setRegion:animated: may adjust the region after the fact. 我知道setRegion:animated:可以在事后调整区域。 And I am aware the a 1m square is an unreasonably small area to attempt to show on a fairly large map. 而且我知道一个1m的正方形是试图在相当大的地图上显示的不合理的小区域。 So, I've tried 所以,我试过了

[self.map setRegion:[self.map regionsThatFits:region] animated:NO];

Setting animated:YES does seem to prevent this from occurring, but I do not want to animate these changes. 设置animated:YES似乎可以防止这种情况的发生,但是我不想为这些更改设置动画。

A few more observations: 一些观察:

  • If I zoom out just 1 or 2 pixels, the map imagery appears. 如果仅缩小1或2像素,则会显示地图图像。
  • Attempting to implement the map delegate method: – mapViewDidFailLoadingMap:withError: does not help. 尝试实现地图委托方法: – mapViewDidFailLoadingMap:withError:没有帮助。 It never is called. 它永远不会被调用。
  • This seems to be new. 这似乎是新的。 The working version I have of the app in the app store, now exhibits similar issues. 我在应用商店中拥有该应用的工作版本,现在也遇到类似的问题。
  • I have seen this happen in other popular apps recently. 我最近在其他流行的应用程序中看到了这种情况。

Any thoughts on a solution to this, or confirmation that it is a systemic problem? 是否有对此解决方案的任何想法,或确认这是系统性问题?

//fix for ios6
if (region.span.latitudeDelta < .0005f)
    region.span.latitudeDelta = .0005f;
if (!region.span.longitudeDelta < .0005f)
    region.span.longitudeDelta = .0005f;

Make sure your region span for lat/lon isn't set too low and it will clear up. 确保您的纬度/经度区域跨度设置得不太低,并且可以清除。

I ended up subclassing MKMapView and overriding setRegion: . 我最终setRegion:MKMapView子类并覆盖了setRegion: I've created a sample app in Github if anyone is interested in seeing the issue in action, or my solution: 如果有人有兴趣查看实际问题或我的解决方案,我已经在Github中创建了一个示例应用程序:

https://github.com/DeepFriedTwinkie/iOS6MapZoomIssue https://github.com/DeepFriedTwinkie/iOS6MapZoomIssue

My setRegion: method looks like this: 我的setRegion:方法看起来像这样:

- (void) setRegion:(MKCoordinateRegion)region animated:(BOOL)animated {
    @try {
        // Get the zoom level for the proposed region
        double zoomLevel = [self getFineZoomLevelForRegion:region];

        // Check to see if any corrections are needed:
        //     - Zoom level is too big (a very small region)
        //     - We are looking at satellite imagery (Where the issue occurs)
        //     - We have turned on the zoom level protection

        if (zoomLevel >= (MAX_GOOGLE_LEVELS-1) && self.mapType != MKMapTypeStandard && self.protectZoomLevel) {
            NSLog(@"setRegion: Entered Protected Zoom Level");

            // Force the zoom level to be 19 (20 causes the issue)
            MKCoordinateRegion protectedRegion = [self coordinateRegionForZoomLevel:MAX_GOOGLE_LEVELS-1.0 atCoordinate:region.center];
            [super setRegion:protectedRegion animated:animated];
        } else {
            [super setRegion:region animated:animated];
        }
    }
    @catch (NSException *exception) {
        [self setCenterCoordinate:region.center];
    }
}

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

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