【发布时间】: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