我在iPhone iOS 5.0设备上使用了这段代码。一切都很好:
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];
然后我在iPhone 6.0上尝试了一下,它在字符串[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>'
我应该在代码中更改什么?
我认为在像这样setRegion
之前,您必须设置latitude span
和longitude span
,,,,
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];
编辑
在您的情况下[mapView regionThatFits:zoomRegion];
它会产生问题.. 删除它:
MKCoordinateRegion zoomRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
// MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:zoomRegion];
[self.mapView setRegion:zoomRegion animated:NO];