Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get compass direction

I want to show the direction on the screen that phone is facing. For example:

   0
   |- []
   |_
  South --- North

In the above diagram the phone would display "North". Since the user (the stick with 0 for his head) is holding out the phone (the [] in the diagram) pointing north.

I found this example. I understand what it's doing except it seems to calculate yaw, pitch, roll, and inclination. What are those and how would I use them to simply find which way the phone is pointing?

Also this android documentation mentions X, Y, and Z axises but I don't see anywhere that says how those axises correspond to the phone? Is Z going from the bottom of the phone to the top?

like image 878
Greg Avatar asked Sep 22 '10 20:09

Greg


1 Answers

this is how the axis (axiy?) look like.

I couldn't find a link to the cheat sheet I use, but it looked sort of like this.

In summary, you want to register to listen for Sensor.TYPE_ORIENTATION, from the incoming array of values get, value[0] and that should show you your angle (from North I believe).

some example from *android.com

like image 114
bgs Avatar answered Sep 29 '22 17:09

bgs