zoukankan      html  css  js  c++  java
  • 获取海拔高度. 实时气压

    海拔高度

    #import <CoreLocation/CoreLocation.h>
    #import <MapKit/MapKit.h>
    
    
    @property (nonatomic , strong) CLLocationManager * locationManager;
    @property (nonatomic , strong) UILabel * altitude;//海拔
    @property (nonatomic , strong) UILabel * verticalAccuracy;//垂直精度
    
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        self.locationManager.delegate = self;
        [self.locationManager requestAlwaysAuthorization];
        [self.locationManager startUpdatingLocation];
    
    
    //实现回调
    -(void)locationManager:(CLLocationManager *)manager
       didUpdateToLocation:(CLLocation *)newLocation
              fromLocation:(CLLocation *)oldLocation
    {
        float altitude = newLocation.altitude;
        float verticalAccuracy = newLocation.verticalAccuracy;
        NSLog(@"%.2fm == %.2fm",altitude ,verticalAccuracy);
        self.altitude.text = [NSString stringWithFormat:@"海拔高度:%.2fm",altitude];
        self.verticalAccuracy.text = [NSString stringWithFormat:@"垂直精度 :%.2fm",verticalAccuracy];
    }
    
    //error回调
    -(void)locationManager:(CLLocationManager *)manager
          didFailWithError:(NSError *)error
    {
        NSLog(@"error.userInfo:%@
    error.domain:%@",error.userInfo,error.domain);
    }

    实时气压

    #import <CoreMotion/CMAltimeter.h>
    
    
    @property (nonatomic , strong) CMAltimeter *altimeter;
    
    
    
    //检测设备是否支持气压计
        if (![CMAltimeter isRelativeAltitudeAvailable]) {
            NSLog(@"Barometer is not available on this device. Sorry!");
            return;
        }
        
        
        //启用气压计
        
        self.altimeter = [[CMAltimeter alloc]init];
        
        [self.altimeter startRelativeAltitudeUpdatesToQueue:NSOperationQueue.mainQueue withHandler:^(CMAltitudeData * _Nullable altitudeData, NSError * _Nullable error) {
            
            NSLog(@"%lf",[altitudeData.relativeAltitude floatValue]);
            
            NSLog(@"%@",error);
            
        }];

    PS: iphone6以下 气压没有卵用....   iPhone SE 也没有卵用

  • 相关阅读:
    继承在WCF中的问题和解决办法
    bootstrap插件学习-bootstrap.dropdown.js
    C#山寨版本拨号客户端
    关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系
    [源码]Literacy 快速反射读写对象属性,字段
    Hadoop Streaming框架学习(一)
    AOP详解
    SESSION会话技术
    mongodb 备份、还原、导入、导出
    Qt 技巧: 解决未解析的SSL问题
  • 原文地址:https://www.cnblogs.com/-yun/p/7992269.html
Copyright © 2011-2022 走看看