Я работаю с Map Kit в iOS 8, используя Obj-C NOT SWIFT. Я не могу получить местоположение устройства, он установлен на 0.00, 0.00, и я получаю сообщение об ошибке:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Я реализовал: (я пробовал только один за раз и не повезло)
if(IS_OS_8_OR_LATER) {
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
И в info.plist
NSLocationWhenInUseUsageDescription : App would like to use your location.
NSLocationAlwaysUsageDescription : App would like to use your location.
Мне будет предложено разрешить приложению использовать мое местоположение, но после того, как я соглашусь, ничего не изменится. Место указывается как 0,00, 0,00.
Код для отображения местоположения пользователей:
//Get Location
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = self.locationManager.location.coordinate.latitude;
region.center.longitude = self.locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.005f;
region.span.longitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];
Майк.
** РЕДАКТИРОВАТЬ: Просмотреть ответ ниже.