2014-10-06 59 views
0

我希望我的應用可以在iOS和Android設備上工作。設備在Android上偏航

我需要它在設備位於桌面時充當指南針,但沒有磁力計 - 相對偏航對我來說已經足夠了。當設備沒有放平時,我不在乎情況。

在iOS中我存儲的參考位置的第一:

motionManager = [[CMMotionManager alloc] init]; 
[motionManager startDeviceMotionUpdates]; 

...

referenceAttitude = [specific->motionManager.deviceMotion.attitude retain]; 

當我需要相對偏航,我把這種方式:

attitude = specific->motionManager.deviceMotion.attitude; 
[attitude multiplyByInverseOfAttitude:specific->referenceAttitude];  
return attitude.yaw; 

如何在Android中做到這一點?在NDK有一個名爲Android的/ sensor.h文件,但我只能夠得到從隊列ASensorEvent :: vector.roll這是不是角度的旋轉速度,然後計算偏航這樣:

yaw = 0; 

。 ..

yaw += ASensorEvent::vector.roll * dt; 

這對低轉速工作正常,但它是非常不準確的。我如何才能在Android上獲得相對的態度?

回答