CLLocationmanager没有返回位置

时间:2015-03-15 11:36:56

标签: ios cllocationmanager

我想在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或错误。我在设备上测试过。有人可以给我一个指向这里可能出错的指针吗?

1 个答案:

答案 0 :(得分:1)

请确保遵循文档

中的指南

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

尤其是'UIRequiredDeviceCapabilities'键位于您的Info.plist中。