Question

I used this code for iPhone iOS 5.0 device. And everything was OK:

self.mapView = [[[MKMapView alloc]init] autorelease];
mapView.delegate = self;
mapView.frame = CGRectMake(0, 0, 320, 414);
[myView addSubview:mapView];
MKCoordinateRegion zoomRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:zoomRegion];
[mapView setRegion:adjustedRegion animated:NO];

Then I tried it on iPhone 6.0, and it crashes at the string [mapView setRegion:adjustedRegion animated:NO];

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
 reason: 'Invalid Region <center:+0.00000000, +0.00000000 span:+176.06470039, +360.00004292>'

What should I change in my code?

Was it helpful?

Solution 2

EDIT

In your case [mapView regionThatFits:zoomRegion]; it create issues.. remove it :

MKCoordinateRegion zoomRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
   // MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:zoomRegion];
    [self.mapView setRegion:zoomRegion animated:NO];

OTHER TIPS

I think you have to set latitude span and longitude span before setRegion like this,,,,

MKCoordinateRegion zoomRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);

MKCoordinateRegion adjustedRegion;
adjustedRegion.center = self.mapView.userLocation.coordinate;
adjustedRegion.span.latitudeDelta = 0.01;
adjustedRegion.span.longitudeDelta = 0.01;
adjustedRegion = [mapView regionThatFits:zoomRegion];
[mapView setRegion:adjustedRegion animated:NO];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top