Hi all,
In accordance with this example (GPS Tutorial), I want to calculate the distance
Using the additional code below why not accurate to measure the distance?
I compare with other applications, SpeedoMeter is more accurate. Is my code something wrong?
Please help me.
In accordance with this example (GPS Tutorial), I want to calculate the distance
Using the additional code below why not accurate to measure the distance?
I compare with other applications, SpeedoMeter is more accurate. Is my code something wrong?
Please help me.
B4X:
#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 LblJarak As Label
Private StartLocation, EndLocation As Location
Private LatitudeReal, LongitudeReal As Double
Private LatitudeStart, LongitudeEnd As Double
Private Distance As Int
Private StartClick As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Distance = 0
StartClick = False
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)
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
LatitudeReal = Location1.Latitude
LongitudeReal = Location1.Longitude
If StartClick = True Then
EndLocation.Initialize2(LatitudeReal, LongitudeReal)
Distance = Distance + StartLocation.DistanceTo(EndLocation)
Log(Distance) 'Why not
'Reset to start
LatitudeStart = LatitudeReal
LongitudeEnd = LongitudeReal
StartLocation.Initialize2(LatitudeStart, LongitudeEnd)
End If
End Sub
Sub BtnStart_Click
StartClick = True
StartLocation.Initialize2(LatitudeReal, LongitudeReal)
EndLocation.Initialize2(LatitudeReal, LongitudeReal)
End Sub