1

我的这段代码适用于 iOS 6,但不会对 iOS 7 产生影响。当设置跨度不起作用时,如何让它适用于 iOS 7?

CLLocationCoordinate2D  ctrpoint = self.location.coordinate;


MapPoint *mp = [[MapPoint alloc] initWithCoordinate:ctrpoint title:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Pin Name:", @"Pin Name:"),self.pin.name] subtitle:self.pin.cell];
[self.mapView addAnnotation:mp];



MKCoordinateSpan span;

span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;

MKCoordinateRegion region;
region.span = span;
region.center = self.location.coordinate;

[self.mapView setRegion:region animated:YES];
4

2 回答 2

3

正确的方法是使用提供的常量:

- (MKCoordinateRegion)regionForWorld {
    return MKCoordinateRegionForMapRect(MKMapRectWorld);
}

所以

- (void)zoomToWorldAnimated:(BOOL)animated {
    MKCoordinateRegion region = [self regionForWorld];
    [self.mapView setRegion:region animated:animated];
}
于 2013-11-07T15:50:53.973 回答
1
  • 假设 self.mapView 已经合成,我会做这样的事情:

    MKCoordinateRegion region = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance([self.location.coordinate, 800, 800)];
    region.span.latitudeDelta = 0.2;
    region.span.longitudeDelta = 0.2;
    [self.mapView setRegion:region animated:YES];
    
  • 请注意,MKCoordinateRegionMakeWithDistance 中的 800 个值是“CLLocationDistance latitudinalMeters”和“CLLocationDistance verticalMeters”。您可能需要根据您的地图大小和所需的缩放级别来更改这些。

  • 对于地图点,我会做这样的事情:

    MKPointAnnotation *mapPoint = [[MKPointAnnotation alloc] init];
    [mapPoint setCoordinate:self.location.coordinate];
    [mapPoint setTitle:@"Your title"];
    [mapPoint setSubtitle:@"My subtitle"];
    [mapView addAnnotation:mapPoint];
    
  • 我已经在 iOS6 和 iOS7 中对此进行了测试,可以向您保证它工作得很好。

于 2013-11-07T15:16:57.647 回答