您好,欢迎来到筏尚旅游网。
搜索
您的当前位置:首页获取设备当前的海拔高度和垂直高度

获取设备当前的海拔高度和垂直高度

来源:筏尚旅游网

首先导入

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

添加请求权限的key

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>YES</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>YES</string>


然后就可以创建  locationManager 对象

    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

本站由北京市万商天勤律师事务所王兴未律师提供法律服务