为什么我的基本气压计/高程应用程序声明的值与实际的实际高程明显不同?

时间:2019-06-11 05:39:29

标签: ios swift altitude cmaltimeter

我正在研究iOS开发并在iOS上使用CMAltimeter API,并注意到非常简单的应用程序与在应用程序商店中找到的海拔应用程序之间存在一些奇怪的不一致之处:https://apps.apple.com/us/app/my-altitude/id465262694 < / p>

我的应用正在通过以下代码计算测高高度:

import UIKit
import CoreMotion

class FirstViewController: UIViewController {

    let altimeter: CMAltimeter = CMAltimeter()

    @IBOutlet weak var altitudeStatus: UILabel!
    @IBOutlet weak var pressureStatus: UILabel!
    @IBOutlet weak var elevationStatus: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        if CMAltimeter.isRelativeAltitudeAvailable() {
            self.altimeter.startRelativeAltitudeUpdates(to: OperationQueue.main) { (data, error) in
                if let err = error {
                    print(err)
                    return
                }
                if let altitudeData = data {
                    self.altitudeStatus.text = "Relative altitude: " + altitudeData.relativeAltitude.stringValue
                    self.pressureStatus.text = "Pressure: " + altitudeData.pressure.stringValue
                    self.elevationStatus.text = "Elevation: " +
                        String(format:"%f", self.getHypsometricAltitude(kiloPascals: altitudeData.pressure.doubleValue)) + "m"
                }
            }
        }
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        altimeter.stopRelativeAltitudeUpdates()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func getHypsometricAltitude(kiloPascals: Double, celsiusTemp: Double = 15.00) -> Double {
        let p = 101325 / (kiloPascals * 1000)
        let pExponent = 1 / 5.25579
        let pPower = pow(p, pExponent)
        let minusOne = pPower - 1
        let kelvin = celsiusTemp + 273.15
        let multipliedByKelvin = minusOne * kelvin
        let altitude = multipliedByKelvin / 0.0065

        return altitude

    }
}

getHypsometricAltitude函数逻辑是从https://keisan.casio.com/exec/system/1224585971派生的,当插入从iOS高度计API中检索到的相同值时,这些值与表单非常匹配。

上述“我的海拔”应用程序的设置允许在使用气压传感器和不使用气压传感器之间进行切换,并且在使用它时我注意到报告的帕斯卡与我的应用程序匹配,在我的情况下,使用气压计最终会高出约1000帕斯卡传感器。有什么想法吗?

0 个答案:

没有答案