【问题标题】:CLLocation manager not returning locationCLLocation 管理器不返回位置
【发布时间】:2015-03-15 11:36:56
【问题描述】:

我正在尝试在我的 viewDidLoad 方法中使用此代码获取当前位置:

//init the location manager
locationManager = [[CLLocationManager alloc] init];    
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];

我有我的委托方法:

//if it fails to get the location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    self.currentLocation = newLocation;

}

我的 UIViewController 符合 CLLocationManagerDelegate 但是我没有得到任何活动、没有 NSLog 或错误。我已经在设备上进行了测试。有人能给我指点一下这里可能出了什么问题吗?

【问题讨论】:

  • 您是否在项目中激活了 LocationTracking?设备是否询问您是否允许位置跟踪?检查您的系统设置,如果该应用已注册位置
  • 设备从来没有问过我这个号码。似乎也没有注册位置。我想知道是不是因为我使用的是 iOS 8
  • 在这里查看我的答案,这是 w.r.t 的常见问题。 iOS 8 和位置管理器。 stackoverflow.com/questions/26777246/…

标签: ios cllocationmanager


【解决方案1】:

确保您遵循文档中的指南

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

尤其是“UIRequiredDeviceCapabilities”键在您的 Info.plist 中。

【讨论】:

  • 感谢您,现在可以使用了。向后兼容8以下的iOS版本?
猜你喜欢
  • 1970-01-01
  • 2013-05-20
  • 2012-04-23
  • 2014-07-26
  • 2021-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多