iOS CoreMotion - Calculating Height Difference

╄→гoц情女王★ 提交于 2019-12-03 20:57:16

No, this isn't possible. Sorry.

There is a nice paper explaining why this isn't possible but I' can't find it at the moment. If I find it I'll post a link.

But yeah, measuring distance moved by just using the accelerometer etc... isn't possible due mainly to noise that is vastly increased by double integration.

Edit

Also, I think you're confusing Attitude and Altitude.

The former is an object describing the orientation of the device using roll, pitch, yaw, etc... The attitude property of the CMDeviceMotion.

The latter is the height above sea level and isn't available through iOS. The only altitude you can get in iOS is the height a particular point on the earth is above sea-level. But you can't get the device altitude, just the ground's altitude.

Either way, it's still not possible.

Edit

It wasn't a paper. It was a video.

https://www.youtube.com/watch?v=_q_8d0E3tDk

On newer iPhones it is indeed possible to get relative altitude from the included barometer (available from iphone 6). Core Motion has been extended to accomodate this.

CMAltimeter - provides delivery of change-of-altitude events.

CMAltitudeData - encapsulates change-of-altitude events (to metre-level resolution).

This kind of thing should work...

 if CMAltimeter.isRelativeAltitudeAvailable() {
     altimeter.startRelativeAltitudeUpdatesToQueue(altimeterQueue,
     withHandler:
         { (  data:CMAltitudeData?,
             error: NSError?) in
             if let altitudeData = data {
                 self.timeStamp = altitudeData.timestamp
                 self.relativeAltitude = altitudeData.relativeAltitude
             }
         }
     )
 }

We don't get absolute height, just relative height change. Initial height is considered to be 0. So you can't really get a percentage change (wouldn't make any sense), but you can get absolute change in metre-scale accuracy.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!