獲取海拔高度. 實時氣壓


海拔高度

#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:%@\nerror.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 也沒有卵用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM