【发布时间】:2014-05-09 08:31:06
【问题描述】:
我正在尝试为 iOS 和情节提要创建虚拟地图视图演示,以允许获取当前用户位置。在执行方面,我必须滚动和滑动才能找到我的当前位置,但不能设置在我当前位置附近的区域。例如,我应该使用 MK Coordinates 或 MKMap Region 来实现什么?下面是我的 .m 实现代码。
- (void)viewDidLoad
{
[super viewDidLoad];
[_mapView setCenterCoordinate:_mapView.userLocation.location.coordinate animated:YES];
MKAnnotationView *userLocationView = [_mapView viewForAnnotation:_mapView.userLocation];
[userLocationView.superview bringSubviewToFront:userLocationView];
}
【问题讨论】:
-
最简单的选项是将 userTrackingMode 设置为 MKUserTrackingModeFollow。否则,您可以在 didUpdateUserLocation 委托方法中设置地图的中心坐标(不需要 CLLocationManager)。不要尝试直接操作注释视图层次结构(使用bringSubviewToFront 等)。