#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public flp As FusedLocationProvider
Public GeoLocal As GeoData
Private LastLocation As Location
Private inactivity_overpass As Boolean = False
End Sub
Sub Service_Create
flp.Initialize("flp")
flp.Connect
End Sub
Sub flp_ConnectionSuccess
'Log("Connected to location provider")
' Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
Dim rs As ResumableSub = CheckLocationSettingStatus
Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
Dim sc As StatusCodes
If (SettingsResult.GetLocationSettingsStatus.GetStatusCode = sc.SUCCESS) Then
StartLocationUpdates
End If
End Sub
Sub flp_ConnectionFailed(ConnectionResult1 As Int)
'Log("Failed to connect to location provider")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub CheckLocationSettingStatus As ResumableSub
Dim f As LocationSettingsRequestBuilder
f.Initialize
f.AddLocationRequest(CreateLocationRequest)
flp.CheckLocationSettings(f.Build)
Wait For flp_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
Return LocationSettingsResult1
End Sub
Public Sub StartLocationUpdates
flp.RequestLocationUpdates(CreateLocationRequest)
End Sub
Private Sub flp_LocationChanged (Location1 As Location)
If (Utils.NNE(Location1.Latitude) And Utils.NNE(Location1.Longitude)) Then
LastLocation=Location1
End If
UpdateUI(Location1)
End Sub
Private Sub CreateLocationRequest As LocationRequest
Dim lr As LocationRequest
lr.Initialize
lr.SetInterval(0)
lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
lr.SetSmallestDisplacement(1)
Return lr
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
flp.Disconnect
Service.StopAutomaticForeground
End Sub
Sub UpdateUI(Location1 As Location)
GeoLocal = Types.setGeoDataDT("-", "-", "")
If Not(Starter.APP_RESET_INSTALL) Then
DateTime.TimeFormat = "HH:mm:ss"
DateTime.DateFormat = "yyyy-MM-dd"
Dim Data As String = $"$date{DateTime.Now} $time{DateTime.Now}"$ ' ${LastLocation.Time}"$
Dim lat As String = "-"
Dim lon As String = "-"
Try
Dim lat As String = $"${Utils.IfNullOrEmpty(Location1.Latitude, "")}"$
Dim lon As String = $"${Utils.IfNullOrEmpty(Location1.Longitude, "")}"$
Catch
Log(LastException)
Dim lat As String = ""
Dim lon As String = ""
End Try
GeoLocal = Types.setGeoDataDT(lat, lon, Data)
End If
' ToastMessageShow($"LOCL:: Latitude: ${Utils.IfNullOrEmpty(Location1.Latitude, "")}, Logitude: ${Utils.IfNullOrEmpty(Location1.Longitude, "")}"$, False)
End Sub