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定位服务详解
本文详细介绍了如何在iOS8中使用CoreLocation框架进行定位服务,包括请求用户授权、初始化定位管理器、实现位置更新和错误处理等关键步骤,并提供了代码示例。



3254

被折叠的 条评论
为什么被折叠?



