Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the compass direction from azimuth on Android

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

like image 282
Android_enthusiast Avatar asked Sep 08 '11 23:09

Android_enthusiast


People also ask

How do you set azimuth on a compass?

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.

What is azimuth angle Android?

Azimuth (degrees of rotation about the -z axis). This is the angle between the device's current compass direction and magnetic north.

What is orientation sensor in mobile?

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.

What is game rotation vector sensor?

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.


1 Answers

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

like image 124
Yves M. Avatar answered Oct 16 '22 14:10

Yves M.