首页 > 代码库 > ios8定位问题(建议CLLocationManager 和MKMapView 结合使用)
ios8定位问题(建议CLLocationManager 和MKMapView 结合使用)
1.在info.plist中添加key NSLocationWhenInUseUsageDescription、NSLocationAlwaysUsageDescription。
2.CLLocationManager 切记定义成成员变量、或者属性,否则导致不弹出系统提示打开定位提示框
3.直接上代码
#pragma mark - CLLocationManagerDelegate
- (void)startLocation{
self.locationmanager = [[CLLocationManager alloc] init];
self.locationmanager.delegate = self;
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if([self.locationmanager respondsToSelector:@selector(requestAlwaysAuthorization)]){
[self.locationmanager requestWhenInUseAuthorization];
}
break;
case kCLAuthorizationStatusDenied:
[UIAlertView bk_alertViewWithTitle:@"请在设置-隐私-定位服务中开启定位功能!"];
break;
case kCLAuthorizationStatusRestricted:
[UIAlertView bk_alertViewWithTitle:@"定位服务无法使用!"];
default:
break;
}
}
4.开启定位后直接使用MKMapView定位。
ios8定位问题(建议CLLocationManager 和MKMapView 结合使用)