首页 > 代码库 > iOS8中使用CoreLocation定位
iOS8中使用CoreLocation定位
iOS8以前使用CoreLocation定位
1 | @property (nonatomic, strong) CLLocationManager *locationManager; |
1 2 3 4 5 | self.locationManager = [[CLLocationManager alloc]init]; _locationManager.delegate = self; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.distanceFilter = 10; [_locationManager startUpdatingLocation]; |
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *currLocation = [locations lastObject]; NSLog(@"经度=%f 纬度=%f 高度=%f", currLocation.coordinrdinate.longitude, currLocation.altitude); } |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { if ([error code] == kCLErrorDenied) { //访问被拒绝 } if ([error code] == kCLErrorLocationUnknown) { //无法获取位置信息 } } |
- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [_locationManager stopUpdatingLocation]; } |
iOS8中使用CoreLocation定位
self.locationManager = [[CLLocationManager alloc]init]; _locationManager.delegate = self; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.distanceFilter = 10; [_locationManager requestAlwaysAuthorization]; //添加这句[_locationManager startUpdatingLocation]; |
iOS8中使用CoreLocation定位
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。