Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Mapview Current Location not fire

MKMapview current user location not fire in iOS-8,previous iOS-7 & iOS-6 are working fine.

     self.mapView.delegate = self;
     self.mapView.showsUserLocation =YES; 

In this line to call automatically the user current location delegate methods

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

but it not fire in iOS-8.

like image 708
user1418679 Avatar asked Sep 18 '14 11:09

user1418679


2 Answers

In iOS8, you need to request user's authorization before getting their location.

There are two kinds of request:

-[CLLocationManager requestWhenInUseAuthorization] lets you get users' location only when the app is awaken.

-[CLLocationManager requestAlwaysAuthorization] lets you get users' location even when it's in the background.

You can choose between them accordingly.

For example, put this before you start updating location:

// ask for authorization
CLLocationManager * locationManager = [[CLLocationManager alloc] init];
// check before requesting, otherwise it might crash in older version
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { 

     [locationManager requestWhenInUseAuthorization];

}

Furthermore, don't forget to add two keys

NSLocationWhenInUseUsageDescription

and

NSLocationAlwaysUsageDescription

into your info.plist.

Leave the values empty to use the default messages or you can customize your own by inputting the values.

like image 80
Tim Chen Avatar answered Oct 08 '22 16:10

Tim Chen


In ios 8 Authorization is required as below

    NSString * osVersion = [[UIDevice currentDevice] systemVersion];
    if ([osVersion floatValue]>= 8.0 ) {
    [_CLLocationManager requestAlwaysAuthorization]; //Requests permission to use location services whenever the app is running. 
// [_CLLocationManager requestWhenInUseAuthorization]; //Requests permission to use location services while the app is in the foreground. 
    }
    [_CLLocationManager startUpdatingLocation];

And you need to add two keys in the plist

1.NSLocationAlwaysUsageDescription

2.NSLocationWhenInUseUsageDescription

enter image description here

like image 44
Ramesh Muthe Avatar answered Oct 08 '22 17:10

Ramesh Muthe