首先导入
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
添加请求权限的key
<key>NSLocationWhenInUseUsageDescription</key>
<string>YES</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>YES</string>
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { float altitude = newLocation.altitude; NSLog(@"海拔高度为:%.2fm",altitude); NSLog(@"垂直精度为:%.2fm",newLocation.verticalAccuracy); }
出现错误
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"%@",error); }
此文章只做学习记录
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- efsc.cn 版权所有 赣ICP备2024042792号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务