Getting magnetic field results as degrees

by Mark Murphy » Tue, 15 Dec 2009 08:45:31 GMT


Sponsored Links
 


That's because you don't.

 http://github.com/commonsguy/cw-advandroid/tree/master/Sensor/Compass/ 

Or, to quote from the docs:

"Sensor.TYPE_ORIENTATION:

All values are angles in degrees.

values[0]: Azimuth, angle between the magnetic north direction and the Y
axis, around the Z axis (0 to 359). 0=North, 90=East, 180=South, 270=West"

 http://developer.android.com/reference/android/hardware/SensorEvent.html 

What you are trying to do is not use the compass
(Sensor.TYPE_ORIENTATION), but rather the raw magnetic field
(Sensor.TYPE_MAGNETIC_FIELD). *That* might need trigonometry to achieve
what you need, but I suspect the vast majority of things that need the
compass can just use the degrees supplied by the compass.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Consulting/App Development:  http://commonsware.com/consulting 

--



Other Threads

1. Repository Grief

I have only recently tried to build Android from the repository.

"repo sync" keeps failing (example below), does anybody know of a
workaround?

Thank you.

g...@cornfed:209>repo sync
Fetching projects:  90% (128/142)  warning: no common commits
remote: Counting objects: 2279, done.
remote: Compressing objects: 100% (1187/1187), done.
fatal: pack has bad object at offset 24477965: inflate returned -5
fatal: index-pack failed
error: Cannot fetch platform/prebuilt
fatal: write error (Broken pipe)
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Guy Cole "Expert Plain And Fancy Bit Twiddling" guyc...@gmail.com

-- 

2. How to configure your application to ensure proper display on Motorola Droid?

Hi Dexter.

Take a look at the technical spec sheet for the Droid where the screen
size and other technical information is detailed:
http://developer.motorola.com/products/droid/
Obviously Droid is Eclair so you will need to ensure that the Android
SDK and ADT Plugin (if you are using Eclipse) are the correct versions
and you will need to compile your application against the Android 2.0
libraries.
For your information the Droid screen size is: WVGA (480 x 854), up to
16M colours and a pixel density of 240dpi.

With regards,

Alex.




-- 

3. DDMS from Eclipse doesn't send geo location to emulator.

4. openInputStream(uri) vs openFileDescriptor(uri, "r")

5. Flicker problem with animation

6. Asynchronous Server Call

7. Improving the Donut VoiceDialer