2017-01-23 2 views
0

SensorEvent API私は別のセンサー(具体的にはTYPE_ROTATION_VECTOR、TYPE_GRAVITY、TYPE_GYROSCOPE、TYPE_LINEAR_ACCELERATION)から自分のアプリのデータを取得するためにSensorEvent APIを使用しています。さて、iOSでは、CMAttitudeReferenceFrameXTrueNorthZVerticalという名前があり、True Northのすべてのセンサー値を与えていますが、z軸は常に垂直です。true north androidに関するセンサーデータ

Androidで似たようなものが見つかりませんでしたので、座標系を手動で翻訳することを考えています。私はremapCoordinateSystem methodを使用することも考えています。しかし、私はまだ真ノースに関してデータを取得する方法を知らない。誰かがこれまでに似たようなものを扱わなければならなかったか?

+0

を使用することができます度に真北を取得するにはSensorEventListener

@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { //get the rotation matrix from the sensor (this will be using the magnetic north) SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); //change the coordinate system (your new matrix is in the variable mChangedRotationMatrix) SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mChangedRotationMatrix); //get the orientationMatrix of your new coordinate system SensorManager.getOrientation(mChangedRotationMatrix, mOrientation); //get the magnetic heading float magneticHeading = (float) Math.toDegrees(mOrientation[0]); //adjust accordingly by calculating the true north with either the "computeTrueNorth" method available the above link or the method used in the link below } } 

でonSensorChangedメソッドを持つべきだと思いますあなたの問題は回答されている可能性があります[ここ](http://stackoverflow.com/a/5518318/7071399)乾杯 –

+0

こんにちは、私はそのポストを知っています。しかし、私が必要とするのは、新しい座標系だけでなく、そのポストのような価値があるからです。 – pixie

答えて

0

この回答はhereを使用するクラスに触発さ:

Youtのは、あなたがthis answer

関連する問題