I've tried doing it this way. But If I change the timer duration it gives me problems. Suggestions? Thanks.
B4X:
'Activity module
Sub Process_Globals
Dim GPS1 As GPS
Dim Timer1 As Timer
End Sub
Sub Globals
Dim Loc,LocStart,LocStop As Location
Dim TickCounter As Int
Dim odo,tempOdo As Float
Dim lblOdo As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
GPS1.Initialize("GPS")
Loc.Initialize
LocStart.Initialize
LocStop.Initialize
TickCounter=0
End If
Activity.LoadLayout("main.bal")'a simple layout with a label 'lblOdo'
Timer1.Initialize("Timer1",3000)
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
TickCounter=TickCounter+3
If TickCounter= 6 Then
setStart
End If
If TickCounter= 12 Then
setStop
End If
End Sub
Sub setStart
LocStart=Loc
End Sub
Sub setStop
LocStop=Loc
'tempOdo=LocStart.DistanceTo(LocStop) we need a control (see following posts)
'added:
If LocStart.Latitude <> 0.0 Then
If LocStart.Longitude <> 0.0 Then
If LocStop.Latitude <> 0.0 Then
If LocStop.Longitude <> 0.0 Then
tempOdo=LocStart.DistanceTo(LocStop)
End If
End If
End If
End If
'end added
odo= odo + tempOdo
lblOdo.text= ("odo: " & Floor(odo) & " m")
TickCounter=0
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device before running 'odoometer' ", True)
Activity.Finish
Else
GPS1.Start(0,0)
Timer1.Enabled=True
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
Timer1.Enabled=False
End Sub
Sub GPS_LocationChanged(Location1 As Location)
Loc=Location1
End Sub
Last edited: