为什么我的 userLocation.location 总是零?

Why is my userLocation.location always nil?

我有 mkmapview 委托来处理授权事件等,但是,我的 userLocation 是真实的,但我的 userLocation.location 在模拟器或设备上总是 returns nil。

关于原因的任何指示?

确保您已添加:

NSLocationWhenInUseUsageDescription in your info.plist project file

Register for CLLocationManagerDelegate

mapView.showsUserLocation=YES;

- (void)viewDidLoad {
      [super viewDidLoad];
      locationManager = [[CLLocationManager alloc] init];
      [locationManager requestWhenInUseAuthorization];
      [locationManager startUpdatingLocation];
}

希望对您有所帮助

在您的设备上测试此行为更简单(或者不要忘记在您的模拟器配置中设置一个位置)