Hi Everyone,
Thanks for the replies. I will be using the phone library and the GPS library to do it.
My target coordinates to face are at latitude 29.907371 and longitude 31.184603 so I used this from the GPS library by adding the following code to the GPS library sample app.
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: GPS
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#End Region
#BridgeLogger: true
Sub Process_Globals
End Sub
Sub Globals
Dim lblLon As Label
Dim lblLat As Label
Dim lblSpeed As Label
Dim lblSatellites As Label
Private LabelQibla As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
If Starter.GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(Starter.GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then CallSubDelayed(Starter, "StartGPS")
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
CallSubDelayed(Starter, "StopGPS")
End Sub
Public Sub GpsStatus (Satellites As List)
Dim sb As StringBuilder
sb.Initialize
sb.Append("Satellites:").Append(CRLF)
For i = 0 To Satellites.Size - 1
Dim Satellite As GPSSatellite = Satellites.Get(i)
sb.Append(CRLF).Append(Satellite.Prn).Append($" $1.2{Satellite.Snr}"$).Append(" ").Append(Satellite.UsedInFix)
sb.Append(" ").Append($" $1.2{Satellite.Azimuth}"$).Append($" $1.2{Satellite.Elevation}"$)
Next
lblSatellites.Text = sb.ToString
End Sub
Public Sub LocationChanged(Location1 As Location)
Dim locQibla As Location
locQibla.Initialize2("29.907371", "31.184603")
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
LabelQibla.Text = "Qibla = " & Location1.BearingTo(locQibla)
End Sub
This above coding returned 58.6 degrees. I also checked a web site that calculates the same thing and it came up with 60 degrees. I imagine the GPS library was more accurate.
I got the phone bearing using this coding:
#Region Project Attributes
#ApplicationLabel: Compass Heading
#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 LabelCompassHeading As Label
Private emad2 As PhoneOrientation
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
emad2.StartListening("Emad2")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Emad2_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
LabelCompassHeading.Text = NumberFormat(Azimuth,3,0)
End Sub
When my bearing was at 59 degrees. I achieved what I needed.
Thanks Erel for that GPS and phone library.
Thanks Syd for the link on calibrating the compass. I will read it to see if it can be done. I was actually going ask about that on another thread.