Android Question Howto - Time remaining before next gps fix?

Mark Read

Well-Known Member
Licensed User
Longtime User
Using the OSMDroid library from Warwound and in particular the MyLocationOverlay, the gps function is activated by enabling the function: MyLocationEnabled.

I need to start a timer [done that] which is started at the same time as the gps and counts up or down with a display on the screen. When the next fix has been found (ca. 15 minutes later), the timer should reset and start again.

I think I can manage this using the sub:

B4X:
Sub MyLocationOverlay1_LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
    'Log("MyLocationOverlay1_LocationChanged, Latitude="&NewLocation.Latitude&", Longitude="&NewLocation.Longitude&", IsFirstFix="&IsFirstFix)
    SimpleLocationOverlay1.SetMyLocation2( NewLocation)
    MapView1.SetCenter2(NewLocation)
    SpeedKmh=NewLocation.Speed*3.6
    acc=NumberFormat2(NewLocation.Accuracy,0,0,0,False)
    Activity.Title="OSMDroid ["&MapView1.Zoom&"] - GPS Accuracy: "&acc&" m: Speed: "&SpeedKmh&" km/h"
End Sub

and inserting Timer1.stop at the start of the sub and Timer1.enabled at the end. Should work?

But how to count down?
How do I display the timer (is probably dead simple)?

Thanks for any help.
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Okay, sometimes it helps to go back and read the Janet and John books (the basics). Got the timer working and showing but I can't get the timer to count backwards. This has got to be simple. This code is working.

B4X:
Sub Timer1_Tick
  'Handle tick events
  periode1 = DateUtils.PeriodBetween( TimerStart,DateTime.Now)
  TimerLabel.Text=periode1.Minutes & ":" & periode1.Seconds
End Sub
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
You can't make the timer count down. You need to use what you already have and subtract the accumulated time from the time you expect it to wait. I'd also add a check to make sure it doesn't go negative. i.e stop at zero.

Regards,
RandomCoder
 
Upvote 0
Top