我想在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或错误。我在设备上测试过。有人可以给我一个指向这里可能出错的指针吗?
答案 0 :(得分:1)
请确保遵循文档
中的指南尤其是'UIRequiredDeviceCapabilities'键位于您的Info.plist中。