iOS Barometer SeaLevel Height

时间:2016-02-23 10:55:30

标签: ios objective-c cmaltimeter

我为登山者制作iOS应用程序以从 SeaLevel 获得高度,目前我被困在这里。我使用iOS Barometer获取详细信息,但它只提供压力,相对高度和时间戳。是否有计算从海平面获得高度? 我正在使用以下方式来获取值。我正在使用 CMAltimeter

NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
formatter.maximumFractionDigits = 2;
formatter.minimumIntegerDigits = 1;

NSNumber *timestamp = [NSNumber numberWithDouble:altitudeData.timestamp];
NSString *timeInterval = [NSString stringWithFormat:@"%@", [formatter stringFromNumber:timestamp]];
NSString *altitude = [NSString stringWithFormat:@"%@", [formatter stringFromNumber:altitudeData.relativeAltitude]];
NSString *pressure = [NSString stringWithFormat:@"%@", [formatter stringFromNumber:altitudeData.pressure]];

self.label1.text = [NSString stringWithFormat:@"Time Interval: \n%@", timeInterval];
self.label2.text = [NSString stringWithFormat:@"Relative Altitude: \n%@", altitude];
self.label3.text = [NSString stringWithFormat:@"Air Pressure: \n%@", pressure];

1 个答案:

答案 0 :(得分:5)

请注意,这只适用于iPhone 6及更高版本,因为只有内置晴雨表才能使用。你想要的公式称为测量公式。

P0 is sea-level pressure in hPa
P is atmospheric pressure in hPa
T is temperature in C
h is altitude in meters

enter image description here

#include <math.h>
h = ((pow(p0/p,1/5.257)-1)*(t+273.15))/0.0065;