Compass for android (orientation in 3D space)

by mboehmer » Mon, 29 Dec 2008 18:19:14 GMT

Sponsored Links

mobile phones usually show the point of the compass, when people are
on the move (estimation of a vector from gps track). The API says,
that android is also able to get the point of the compass. How is this
done? Is this done by software (estimating the vector) or has the G1
an build-in magnetic hardware compass? If not, does anyone know, if it
is possible to connect a magnetic compass via USB or bluetooth?

I am interested in the orientation of the phone in 3D space, while the
user is standing still. Does anyone know, how wikitude (http:// does this?

Best regards


Compass for android (orientation in 3D space)

by DSmith » Mon, 29 Dec 2008 23:44:16 GMT

 The easiest way is to use SENSOR_ORIENTATION ( 
SensorManager.html#SENSOR_ORIENTATION).  It does all the necessary
calculations on the magnetometer and accelerometer values, throws in
some low-pass filtering, and spits out azimuth, pitch, and roll.  The
calculations aren't perfect - you'll see some strange things at the
branch cuts, like the az spinning backwards through the entire range
when you raise the phone over your head, but it's pretty good for most
practical uses.

Sponsored Links

Other Threads

1. How to make the consistent WebView (not lauching a new Web browser?)

Hi, I have a question about using WebView.

When I load a WebView, it is lauching a new Web browser? (it means
another application is lauched)
I want that the next linked response has contained the previous
WebView, not the new one.

When a link in the WebView was clicked, how to keep the WebView layout

Thanks in advance for ur replies.


2. why my onScrollStateChanged(AbsListView view, int scrollState) effetct nothing

I use ListActivity , and implements OnScrollListener, and have my code
just like below
public void onScroll(AbsListView view, int firstVisibleItem, int
visibleItemCount, int totalItemCount) {
        Toast.makeText(this, totalItemCount+"", Toast.LENGTH_SHORT).show();

public void onScrollStateChanged(AbsListView view, int scrollState) {
        Toast.makeText(this, "onScrollStateChanged",

every time I scroll the listview, and ddms output  "onScroll"
right .but when I scroll to the end and still scroll. It seems the
ddms should ouput onScrollStateChanged and have a toast, but it
doesn't. why?


3. Is WIFI default mode of communcation to internet

4. How to register to Internet browser URL change events

5. Stream Sound Delay

6. how to get the total size of sdcard?

7. Can't use service with AIDL right after starting it with bindservice and BIND_AUTO_CREATE