此代码我已经适用于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];
答案 0 :(得分:3)
正确的方法是使用提供的常量:
- (MKCoordinateRegion)regionForWorld {
return MKCoordinateRegionForMapRect(MKMapRectWorld);
}
所以
- (void)zoomToWorldAnimated:(BOOL)animated {
MKCoordinateRegion region = [self regionForWorld];
[self.mapView setRegion:region animated:animated];
}
答案 1 :(得分: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 longitudinalMeters”。您可能需要根据地图大小和所需的缩放级别更改这些内容。
对于地图点我会做这样的事情:
MKPointAnnotation *mapPoint = [[MKPointAnnotation alloc] init];
[mapPoint setCoordinate:self.location.coordinate];
[mapPoint setTitle:@"Your title"];
[mapPoint setSubtitle:@"My subtitle"];
[mapView addAnnotation:mapPoint];
我已经在iOS6和iOS7中对此进行了测试,可以保证它的工作正常。