我的 View (MKMapViewDelegate) 上有一个启用了“显示用户位置”的 mapView socket 。
在我拥有的那个 Controller 的 viewdidload 中
CLLocation *userLoc = mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
mapView.delegate=self;
模拟器在 map 上显示了正确的用户位置(我在 IOS 模拟器中使用自定义位置)
但是 NSLog 显示纬度和经度为 0 和 0。
难道我不能在模拟器中获取自定义的经纬度吗?
更新答案:
需要实现
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.centerCoordinate = userLocation.location.coordinate;
}
最佳答案
位置服务不是即时的。您的代码在 viewDidLoad
中,因此它还没有机会确定您的位置。您应该将 map View 的 delegate
属性设置为实现 MKMapViewDelegate
协议(protocol)的对象。
关于ios - MKMapView userLocation 在模拟器中显示 0,0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9619100/