无法在我的应用中启用该位置

时间:2012-12-12 08:09:02

标签: ios

我想在我的应用中找到我的位置。我use CoreLocationManager得到坐标,但是当我启动应用程序时,它会提醒我天气以授权位置隐私,在我点击确定按钮后,什么也没发生。

然后我在iPhone中打开设置 - 隐私位置,我发现我的应用程序未启用该位置。我打开它,然后我重新启动应用程序,仍然没有发生什么?

这是我的代码:

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray   *)locations
{

}

设置断点后,方法-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations无法运行。

1 个答案:

答案 0 :(得分:1)

使用以下代码在您的设备中获取当前的经度和纬度(不在模拟器中)。

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
latitude = [[NSString alloc] initWithFormat:@"%f", coordinate.latitude];
longitude = [[NSString alloc] initWithFormat:@"%f", coordinate.longitude];
NSLog(@"dLatitude : %@", latitude);
NSLog(@"dLongitude : %@",longitude);