MKCoordinateRegion setRegion issue



我在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 spanlongitude 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];

相关内容

  • 没有找到相关文章

最新更新