0

我想在我的应用程序中找到我的位置。而且我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无法运行。

4

1 回答 1

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);
于 2012-12-12T09:17:21.743 回答