The GPS locations service has functions to get Lat, Lon, Bearing, Speed, etc. What seems to be missing is a way to get the magnetic declination. I tried the code below to use the native java function but it gives a compiler error code.
How can I get the magnetic Declination at a specified Lat/Lon/Altitude?
Thanks in advance!
Compiler error:
B4a code:
How can I get the magnetic Declination at a specified Lat/Lon/Altitude?
Thanks in advance!
Compiler error:
B4X:
Generating R file. (0.69s)
Compiling generated Java code. Error
javac 1.8.0_181
src\com\calypsoinstruments\CalypsoUltrasonicAPI\main.java:1124: error: cannot find symbol
GeomagneticField mGeoField = new GeomagneticField(Lat, Lon, Altitude, Millis);
^
symbol: class GeomagneticField
location: class main
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
B4a code:
B4X:
Public gpsManager As GPS
Public javaInline As JavaObject
..
gpsManager.Initialize("GPS")
Starter.javaInline.InitializeContext
...
Sub GPS_LocationChanged(myLocation As Location)
' store the current location data in the global dictionary 'sensorData'
sensorData.Put("LAT", myLocation.Latitude)
sensorData.Put("LON", myLocation.Longitude)
If myLocation.BearingValid Then
sensorData.Put("COG", myLocation.Speed)
Else
sensorData.Put("COG", 0.0)
End If
If myLocation.SpeedValid Then
sensorData.Put("SOG", myLocation.Bearing)
Else
sensorData.Put("SOG", 0.0)
End If
If myLocation.AccuracyValid Then
sensorData.Put("STATUS", myLocation.Accuracy)
Else
sensorData.Put("STATUS", 0.0)
End If
If myLocation.AltitudeValid Then
sensorData.Put("ALT", myLocation.Altitude)
Else
sensorData.Put("ALT", 10.0)
End If
If localDeclination = 999 Then
localDeclination = magDeclination ' get the magnetic delication at the current location & altitude
End If
sensorData.Put("DEC", localDeclination)
End Sub
Sub magDeclination() As Float
' get the magnetic declination for the current location
Dim magDec As Float = 0.0 ' default value
#if B4A
Dim millis As Long = DateTime.Now
magDec = javaInline.RunMethod("getDeclination", Array As Object(sensorData.Get("LAT"), sensorData.Get("LON"), sensorData.Get("ALT"), millis))
Log("Starter->magDeclination(): mag Declination = " & magDec & " | " & millis)
#end if
Return magDec
End Sub
#If JAVA
public float getDeclination(float Lat, float Lon, float Altitude, long Millis) {
GeomagneticField mGeoField = new GeomagneticField(Lat, Lon, Altitude, Millis);
return mGeoField.getDeclination();
}
#End If