Dear Experts,

I'm trying to understand how to get simple compass functionality
working, i.e. I have a map that I want to add a "facing this way"
arrow to.  I don't need other orientation angles i.e. it's not
Augmented Reality, but I do need it to work correctly as the display
orientation changes.  I know about magnetic deviation but will
overlook it in this post.

As far as I can see, there is a reasonably simple deprecated method: I
getDefaultSensor(TYPE_ORIENTATION), and use values[0].  It's
unfortunate that this is deprecated.

The replacement for this deprecated method seems to be:
1. getDefaultSensor(TYPE_GRAVITY) and
getDefaultSensor(TYPE_MAGNETIC_FIELD)
2. When I have new values from both sensors (which don't necessarily
arrive at the same rate), pass them to getRotationMatrix() and then
pass the rotation matrix to getOrientation() to get the angles.

...but that doesn't allow for the display orientation.  I think that I
need to get that (from where?) and subtract it from the result.

...and I also don't think it does the right thing when I am holding
the device near-vertically.  Say you're standing, facing East, holding
the device in front of your face, viewing a map; it will have East at
the top.  But if you tilt the device so it is slightly "overhanging",
this method will flip it so that West is at the top, won't it?  That's
certainly not what the user would expect.

...and I don't really think the accelerometer is needed for this.  I
think the accelerometer is only really needed to get the two other
outputs (pitch and roll) from getOrientation() that I ignore.  Though
I may be wrong about that, if I fix the previous issue, due to varying
magnetic dip angles.

So, has anyone else worked out how all of this should hang together?
Is there some simpler API somewhere that I have missed?


Thanks,  Phil.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to