Looked into this a little, sounds like an interesting project. Unfortunately, it looks like this would be difficult data to get at from a javascript framework.
There was a W3C recommendation back in 2009 for the Compass API, which included the fieldStrength attribute, a perfect fit for what you are doing.
http://dev.w3.org/2009/dap/system-info/compass.html
Unfortunately, it doesn't look like fieldStrength was exposed in any version of phonegap I can find. It doesn't look like CocoonJS implemented any compass features at all.
Apparently, not all devices that offer compass data use a magnetometer either. However, all iPads, and all iPhones since the 3GS, do have true magnetometers. Many android devices have them, but some don't.
Here are links to the low-level API documentation for magnetometer data on android and iOS:
Android:
http://developer.android.com/guide/topi ... rs-pos-mag
iOS:
https://developer.apple.com/library/ios ... index.html