Java tutorial
//package com.java2s; /***************************************************************************************** * Android Java Interface for Razor AHRS v1.4.1 * 9 Degree of Measurement Attitude and Heading Reference System * for Sparkfun "9DOF Razor IMU" and "9DOF Sensor Stick" * * Released under GNU GPL (General Public License) v3.0 * Copyright (C) 2013 Peter Bartz [http://ptrbrtz.net] * Copyright (C) 2011-2012 Quality & Usability Lab, Deutsche Telekom Laboratories, TU Berlin * Written by Peter Bartz (peter-bartz@gmx.de) * * Infos, updates, bug reports, contributions and feedback: * https://github.com/ptrbrtz/razor-9dof-ahrs ******************************************************************************************/ import android.hardware.GeomagneticField; import android.location.Location; public class Main { /** * Returns declination in degrees at given location * * @param location * @return Declination in degrees */ public static float getDeclinationAt(Location location) { return getDeclinationAt((float) location.getLatitude(), (float) location.getLongitude(), (float) location.getAltitude()); } /** * Returns declination in degrees at given location * * @param location * @return Declination in degrees */ public static float getDeclinationAt(float latitude, float longitude, float altitude) { GeomagneticField gf = new GeomagneticField(latitude, longitude, altitude, System.currentTimeMillis()); return gf.getDeclination(); } }