正確讓ios8定位的方法來了:
1.在Info.plist表裏面添加兩個變量
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
(這兩個字段沒什麼特別的意思,就是自定義提示用戶授權使用地理定位功能時的提示語)
2.添加代碼:
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
調用代理:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
break;
default:
break;
}
}
3.這樣就可以打開地圖定位功能了!
最近在做基於百度Map定位及路線軌跡的功能!完成後,也發出來供大家學習使用,盡情期待吧~
(後續)
最近手機升級到ios8以上,發現地圖又無法定位了!
各種求救,最後找到解決方法!
ios8對定位做了一些調整,
1.@interface裏:
CLLocationManager *locationManager;
2.locationManager=[[CLLcationManager alloc]init];
if([[[UIDevice currentDevice]systemVersion]doubleValue]>8.0)
{
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];