I have to display which direction the user is pointing the Android device.
I am using Sensor.TYPE_ACCELEROMETER
, Sensor.TYPE_MAGNETIC_FIELD
to get the azimuth, pitch, roll. But I am to able to figure out how to get directions (North, south, east , west,...) from this.
Please help
Thanks
Set the azimuth on the compass by turning the degree dial until the desired azimuth lines up with the direction-of-travel arrow. c. While holding the compass in front of you, turn until the needle lines up with the orienting arrow.
Azimuth (degrees of rotation about the -z axis). This is the angle between the device's current compass direction and magnetic north.
The digital compass that's usually based on a sensor called the magnetometer and provides mobile phones with a simple orientation in relation to the Earth's magnetic field. As a result, your phone always knows which way is North so it can auto rotate your digital maps depending on your physical orientation.
A game rotation vector sensor is similar to a rotation vector sensor but not using the geomagnetic field. Therefore the Y axis doesn't point north but instead to some other reference. That reference is allowed to drift by the same order of magnitude as the gyroscope drifts around the Z axis.
To point the north you can calculate a rotation in degrees :
float rotation = -azimut * 360 / (2 * 3.14159f);
You can see the following compass example which make uses of accelerometer and magnetic field : http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html
Azimuth on Wikipédia : http://en.wikipedia.org/wiki/Azimuth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With