MKMapView setRegion to Small Area crashes loading satellite image

I have been working on the same application for several months, and this is a new problem. I am wondering if there have been any changes on the side of the Apple Map data server. Here's the problem:

My application (from time to time) wants to set the MKMapView area to the highest possible scalable value in a specific location. For this, I am doing something like:

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

No matter where the item's coordinate is, I get a background with a β€œno satellite imagery” grid. This does not appear to be related to satellite imagery, as it behaves consistently in many areas of the United States.

I know that setRegion:animated: can adjust the area after the fact. And I know that a 1 m square is an unreasonably small area to try to show on a rather large map. So I tried

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

Setting animated:YES really prevents this from happening, but I don't want to animate these changes.

A few observations:

  • If I reduce only 1 or 2 pixels, a map image appears.
  • Trying to implement a map delegation method: – mapViewDidFailLoadingMap:withError: does not help. He is never called.
  • It seems new. The working version that I have in the app in the app store now shows similar problems.
  • I recently saw this in other popular apps.

Any thoughts on resolving this issue or confirming that this is a system problem?

+4
source share
2 answers

I ended up subclassing MKMapView and overriding setRegion: I created an example application on Github if someone is interested in seeing a problem in action or my solution:

https://github.com/DeepFriedTwinkie/iOS6MapZoomIssue

My setRegion: method looks like this:

 - (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]; } } 
+1
source
 //fix for ios6 if (region.span.latitudeDelta < .0005f) region.span.latitudeDelta = .0005f; if (!region.span.longitudeDelta < .0005f) region.span.longitudeDelta = .0005f; 

Make sure the area range for lat / lon is not set too low and it will clear up.

+1
source

Source: https://habr.com/ru/post/1479825/


All Articles