Мое приложение Xcode, которое я разрабатываю, должно получить широту и долготу устройства iOS пользователей. Хотя в настоящее время все, что я получаю, равно 0 для обоих значений. Он не запрашивает разрешения на местоположение, и я нахожусь на настоящем устройстве, а не в симуляторе.Текущее местоположение, возвращаемое 0
NSLocationAlwaysUsageDescription
в моем info.plist
Я также импортирован CoreLocation и в моем файле .h
@interface LocationViewController : UIViewController <CLLocationManagerDelegate>
в моем файле .m
@interface LocationViewController() <CLLocationManagerDelegate>
Вот мой код:
@implementation LocationViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self getCurrentLocation];
}
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}
который iOS? Я считаю, что вы тестируете iOS 8 и выше ... верно? –
Да iOS 8.2, спасибо :) –