Have done this just for the fun of it. Have wrapped
this posting. The B4A code is short and sweet:
#Region Project Attributes
#ApplicationLabel: Compass
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private c1 As Compass
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
c1.registerListener
End Sub
Sub Activity_Pause (UserClosed As Boolean)
c1.unregisterListener
End Sub
Sub c1_current_orientation(orient As Int)
Label1.Text = "Degrees from North = " & orient
End Sub
View attachment 43082
Library:
Compass
Author: Author: Marko Gargenta, Wrapped by: Johan Schoeman
Version: 1
Posting the B4A project, the B4A lib files, and the Java Code. Take note of the Objects/res/drawable folder of the B4A project - it contains the "compass rose".
Place your device on a flat surface and then turn it CW / ACW.