I need to build compass for my application.
From reading the documentation it seems there are two reasonable ways of doing this:
Any suggestions for solving this problem will be greatly appreciated.
Looks like mob1lejunkie has figured this out already, but just for future reference, let me mention that the issue here is magnetic declination (the difference between magnetic north and true north). You can try out an online model from NOAA to get a sense for what the difference is in your part of the world.
Android includes a model called GeomagneticField that can be used to compute the approximate declination given a latitude, longitude, and altitude. So, what I believe you need to do to compute true north is read out the azimuth value from Sensor.TYPE_ORIENTATION and then add to that GeomagneticField.getDeclination().
It's the downside of compact parts made for phones. A $5000 IMU that we're using right now has an error of +/- 2 degrees and in that range it seems to go crazy as well.
Try stepping away from interference, metal surfaces, and see if it improves. If not, I hate to break the bad news, but that's the hardware.
Have you seen these?
http://developer.android.com/reference/android/hardware/SensorManager.html
http://groups.google.com/group/android-developers/browse_thread/thread/bbb0e8b97c673cf9/5c16bc2e49f6e972?lnk=raot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With