Sub Class_Globals
Private jo As JavaObject
Public Declination As Float
Public Inclination As Float
Public TotalStrength As Float
Public HorizontalStrength As Float
Public X As Float
Public Y As Float
Public Z As Float
End Sub
'Initialize the geomagnetic
Public Sub Initialize(Latitude As Float, Longitude As Float, Altitude As Float, Time As Long)
jo.InitializeNewInstance("android.hardware.GeomagneticField", Array As Object(Latitude, Longitude, Altitude, Time))
Refresh
End Sub
'Reload all properties
Public Sub Refresh
Declination = jo.RunMethod("getDeclination", Null)
Inclination = jo.RunMethod("getInclination", Null)
TotalStrength = jo.RunMethod("getFieldStrength", Null)
HorizontalStrength = jo.RunMethod("getHorizontalStrength", Null)
X = jo.RunMethod("getX", Null)
Y = jo.RunMethod("getY", Null)
Z = jo.RunMethod("getZ", Null)
End Sub
'Converts a magnetic heading into a true heading.
Public Sub MagneticToTrue(MagneticHeading As Float) As Float
Dim h As Float = MagneticHeading + Declination
Do While h < 0
h = h + 360
Loop
Do While h >= 360
h = h - 360
Loop
Return h
End Sub
'Converts a true heading to a magnetic heading
Public Sub TrueToMagnetic(TrueHeading As Float) As Float
Dim h As Float = TrueHeading - Declination
Do While h < 0
h = h + 360
Loop
Do While h >= 360
h = h - 360
Loop
Return h
End Sub