6

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?

OldTroll
  • 773
  • 6
  • 22
Greg
  • 45,306
  • 89
  • 231
  • 297
  • 1
    http://en.wikipedia.org/wiki/Yaw_angle – Falmarri Sep 22 '10 at 20:42
  • I also noticed the GeomagneticField class has getX and getY methods? Can I use that instead? It doesn't have any kind of sensorChanged altert though. Would I have to make my own loop to poll it? – Greg Sep 22 '10 at 20:43
  • This article might be useful to you. You need to be caerful about assumptions about screen orientation when displaying directions on teh screen. http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html – Cheryl Simon Sep 22 '10 at 20:49

1 Answers1

5

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

bgs
  • 1,210
  • 10
  • 19
  • Thanks. What happens if the phone is in landscape mode? – Greg Sep 23 '10 at 18:06
  • according to this post, http://www.google.com/support/forum/p/android/thread?tid=11b73cc231c318af&hl=en its basically a hardware compass, so it should behave normally in landscape mode – bgs Sep 23 '10 at 20:40
  • 2
    I'd just like to point out that `Sensor.TYPE_ORIENTATION` has been deprecated, in favour of `SensorManager.getOrientation()`. – AlbeyAmakiir Apr 17 '12 at 03:59