我有一个问题。我的当前位置在地图视图中显示并居中,但地图区域不会放大。我尝试通过从 didUpdateToLocation 方法中取出 span 和 region 来采纳 Rob 的建议,但我一定没有正确实施它。我认为它没有识别我在 viewDidLoad 中对 setRegion 的调用,并且我的按钮没有被识别。请检查我下面的代码并指出错误。我的目标是能够使用 IBAction 按钮放大和缩小我的位置。
。H
- (IBAction)zoomIn:(id)sender;
- (IBAction)zoomOut:(id)sender;
.m 在 viewDidLoad
double miles = 0.5;
MKCoordinateSpan span;
span.latitudeDelta = miles/69.0;
span.longitudeDelta = miles/69.0;
MKCoordinateRegion region;
region.span = span;
[self.mapView setRegion:region animated:YES];
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
_mapView.mapType = MKMapTypeSatellite;
.m 在我的 didUpdateToLocation 方法中。
[self.mapView setCenterCoordinate:newLocation.coordinate animated:YES];
。放大:
- (IBAction)zoomIn:(id)sender
{
MKCoordinateSpan span;
span.latitudeDelta = _mapView.region.span.latitudeDelta * 2;
span.longitudeDelta = _mapView.region.span.latitudeDelta * 2;
MKCoordinateRegion region;
region.span = span;
region.center = _mapView.region.center;
[self.mapView setRegion:region animated:YES];
}
。缩小 :
- (IBAction)zoomOut:(id)sender
{
MKCoordinateSpan span;
span.latitudeDelta = _mapView.region.span.latitudeDelta / 2;
span.longitudeDelta = _mapView.region.span.latitudeDelta / 2;
MKCoordinateRegion region;
region.span = span;
region.center = _mapView.region.center;
[self.mapView setRegion:region animated:YES];
}