我正在将 map View 加载到 View Controller 的 View 中。当我加载 map View 时,它会直接缩放到联系人的位置。我的 View Controller 的工具栏中有按钮。当我点击这个按钮时, map View 应该从已经缩放的位置缩放到我的 iPhone 的当前位置。该功能与iPhone map 应用程序中的功能类似。我怎样才能做到这一点?
最佳答案
//did update user location
- (void)mapView:(MKMapView *)currentMapView didUpdateUserLocation:(MKUserLocation *)userLocation{
if(shouldChangeSpan) {
MKCoordinateSpan span;
span.latitudeDelta = 0.40;
span.longitudeDelta = 0.45;
MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, span);
[mapView setRegion:region animated:YES];
shouldChangeSpan = NO;
}
}
shouldChangeSpan 中声明的 bool 值。并在 View 确实加载中设置为 no,并在按钮操作方法中设置为 yes。
关于iphone - 如何将 map View 中已缩放的位置更改为当前设备位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9063403/