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?

3
  • 1
    en.wikipedia.org/wiki/Yaw_angle
    – Falmarri
    Sep 22, 2010 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, 2010 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. android-developers.blogspot.com/2010/09/… Sep 22, 2010 at 20:49

1 Answer 1

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

3
  • Thanks. What happens if the phone is in landscape mode?
    – Greg
    Sep 23, 2010 at 18:06
  • according to this post, google.com/support/forum/p/android/… its basically a hardware compass, so it should behave normally in landscape mode
    – bgs
    Sep 23, 2010 at 20:40
  • 2
    I'd just like to point out that Sensor.TYPE_ORIENTATION has been deprecated, in favour of SensorManager.getOrientation(). Apr 17, 2012 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.