简体   繁体   中英

IOS 8 Map is not working: Trying to start MapKit location updates without prompting for location authorization

I am using Xcode 6.I have some problems when I try to get User current Location using CLLocationManager. Even I added the NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription to Info.plist file. And also used [CLLocationManager requestWhenInUseAuthorization] . Then also I am getting console output as

2014-10-15 11:45:15.004 MapIOS8[1916:57908] Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

Have you tried writting the code in this order?

CLLocationManager *YourLocationManager = [[CLLocationManager alloc] init];
YourLocationManager.delegate = self;
[YourLocationManager requestWhenInUseAuthorization];
[YourLocationManager startUpdatingLocation];

yourMapView.delegate = self;
yourMapView.showsUserLocation = YES;

Also, to get the user location coordinate, you may have to implement this mapkit delegate method

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"%f, %f", userLocation.coordinate.latitude, userLocation.coordinate.longitude);

    [mapView selectAnnotation:userLocation animated:YES];
}

If you are using iOS Simulator try to reset location settings from Settings-> General-> Privacy-> Reset location & privacy. Then call:

[LocationManager requestAlwaysAuthorization];

At the first execution must appear a popup to allow the use of the current user's position. After allow the use of current location start your LocationManager with:

[LocationManager startUpdatingLocation];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM