1

我将此代码用于 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>'

我应该在我的代码中更改什么?

4

2 回答 2

4

我认为你必须像这样设置latitude spanlongitude span之前setRegion,,,,

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];
于 2013-01-30T06:58:06.470 回答
0

编辑

在您的情况下[mapView regionThatFits:zoomRegion];,它会产生问题..删除它:

MKCoordinateRegion zoomRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
   // MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:zoomRegion];
    [self.mapView setRegion:zoomRegion animated:NO];
于 2013-01-30T06:56:26.233 回答