mirror of
https://github.com/cheveguerra/FLP_2.0.git
synced 2026-04-17 19:36:42 +00:00
29/9/23 - Correcciones en el envío de la ubicacion.
This commit is contained in:
55
Tracker.bas
55
Tracker.bas
@@ -39,7 +39,7 @@ Sub Process_Globals
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
Public FLP As FusedLocationProvider
|
||||
Private flpStarted As Boolean
|
||||
Dim minAccuracy As Int = 30
|
||||
Dim minAccuracy As Int = 50
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
@@ -50,6 +50,7 @@ Sub Service_Create
|
||||
lock.PartialLock
|
||||
StartFLP
|
||||
If Starter.logger Then Log("FLP initialized")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Iniciamos Tracker', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionSuccess
|
||||
@@ -67,6 +68,7 @@ Sub Service_Start (StartingIntent As Intent)
|
||||
Service.StartForeground(nid, Subs.CreateNotification("..."))
|
||||
Track
|
||||
StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerMinute, True)
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${starter.devModel}', 'Tracker - Service_Start', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Public Sub Track
|
||||
@@ -81,14 +83,14 @@ Public Sub Track
|
||||
End Sub
|
||||
|
||||
Public Sub StartFLP
|
||||
Log("StartFLP - flpStarted="&flpStarted)
|
||||
' Log("StartFLP - flpStarted="&flpStarted)
|
||||
Do While FLP.IsConnected = False
|
||||
Sleep(500)
|
||||
Log("sleeping")
|
||||
Loop
|
||||
' If flpStarted = False Then
|
||||
Log("RequestLocationUpdates")
|
||||
Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
' Log("RequestLocationUpdates")
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
FLP.RequestLocationUpdates(CreateLocationRequest) 'Buscamos ubicacion
|
||||
flpStarted = True
|
||||
' End If
|
||||
@@ -96,7 +98,7 @@ End Sub
|
||||
|
||||
Private Sub CreateLocationRequest As LocationRequest
|
||||
' Log("CreateLocationRequest")
|
||||
Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(30000) 'Intervalo deseado para actualizaciones de ubicacion en milisegundos
|
||||
@@ -106,23 +108,16 @@ Private Sub CreateLocationRequest As LocationRequest
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Sub dameUltimaUbicacionConocida(lastLocation As Location)
|
||||
Sub dameUltimaUbicacionConocida(lastLocation As Location) '
|
||||
If Starter.logger Then LogColor("dameUltimaUbicacionConocida", Colors.Magenta)
|
||||
If FLP.GetLastKnownLocation.IsInitialized Then 'Mandamos ultima ubicacion guardada
|
||||
If Starter.logger Then Log("This accuracy: " & FLP.GetLastKnownLocation.Accuracy)
|
||||
If Starter.logger Then Log("This distance to previous: " & FLP.GetLastKnownLocation.DistanceTo(lastLocation))
|
||||
Dim coords As String = FLP.GetLastKnownLocation.Latitude&","&FLP.GetLastKnownLocation.Longitude&","&Subs.formatoFecha(FLP.GetLastKnownLocation.Time)
|
||||
If FLP.GetLastKnownLocation.Accuracy < minAccuracy And FLP.GetLastKnownLocation.DistanceTo(lastLocation) > 25 Then
|
||||
Starter.UUC = FLP.GetLastKnownLocation
|
||||
Subs.mandaLocAServer(FLP.GetLastKnownLocation, Starter.devModel)
|
||||
If Starter.logger Then Log("Mandamos GetLastKnownLocation : "&DateTime.Time(FLP.GetLastKnownLocation.Time))
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
End If
|
||||
' Log($"ultima actualizacion: ${Starter.lastLocUpdate}"$)
|
||||
' Log($"${DateTime.now} - ${Starter.lastLocUpdate} = ${(DateTime.Now - Starter.lastLocUpdate)/1000}"$)
|
||||
' Log("||" & Subs.ConvertMillisecondsToString((DateTime.Now - Starter.lastLocUpdate)))
|
||||
End If
|
||||
' Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(FECHA INTEGER, LAT TEXT, LON TEXT)")
|
||||
If Starter.logger Then Log("This accuracy: " & Starter.UUC.Accuracy)
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Enviamos UUC - Acc: ${Starter.UUC.Accuracy}, Time:${Starter.UUC.Time}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
Dim coords As String = Starter.UUC.Latitude & ","&Starter.UUC.Longitude & ","&Subs.formatoFecha(Starter.UUC.Time)
|
||||
Subs.mandaLocAServer(Starter.UUC, Starter.devModel)
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
If Starter.logger Then Log("Mandamos GetLastKnownLocation : "&DateTime.Time(FLP.GetLastKnownLocation.Time))
|
||||
If Starter.logger Then Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
End Sub
|
||||
|
||||
Public Sub StopFLP
|
||||
@@ -134,7 +129,9 @@ Public Sub StopFLP
|
||||
End Sub
|
||||
|
||||
Sub flp_LocationChanged (Location1 As Location)
|
||||
Starter.FLPStatus = "Location changed" : LogColor("Location changed", Colors.blue)
|
||||
' Starter.FLPStatus = "Location changed" : LogColor("Location changed", Colors.blue)
|
||||
Dim el_texto As String = ""
|
||||
Starter.UUC = Location1
|
||||
If Not(Starter.Timer1.Enabled) Then Starter.Timer1.Enabled = True : Log("timer enabled")
|
||||
If Starter.logger Then LogColor("FLP_LocationChanged", Colors.Red)
|
||||
' ToastMessageShow("FLP_LocationChanged", False)
|
||||
@@ -146,10 +143,17 @@ Sub flp_LocationChanged (Location1 As Location)
|
||||
If Starter.logger Then Log(Location1)
|
||||
If Starter.logger Then Log(Location1.Accuracy&" - "&Location1.AccuracyValid)
|
||||
' solo mandamos la ubicacion si la precision es dentro de XX mts
|
||||
If Location1.Accuracy < minAccuracy Then CallSubDelayed2(FirebaseMessaging,"mandamosLoc", coords)
|
||||
If Location1.Accuracy < minAccuracy Then Starter.UUC = Location1
|
||||
If Location1.Accuracy < minAccuracy Then Subs.mandaLocAServer(Location1, Starter.devModel)
|
||||
el_texto = $"LocChange - Coords NO enviadas (Acc:${Location1.Accuracy})."$
|
||||
If Location1.Accuracy < minAccuracy Then
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc", coords)
|
||||
Subs.mandaLocAServer(Location1, Starter.devModel)
|
||||
Dim coords As String = Location1.Latitude&","&Location1.Longitude&","&Subs.formatoFecha(Location1.Time)
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
el_texto = $"LocChange - Coords enviadas (Acc:${Location1.Accuracy})."$
|
||||
End If
|
||||
If Starter.logger Then Log("Loc changed : "&Location1.Latitude&","&Location1.Longitude&"|"&Starter.devModel&"|")
|
||||
Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS BITACORA(RUTA TEXT, TEXTO TEXT, FECHA TEXT)")
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', '${el_texto}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
CallSubDelayed(Main, "ponCoords")
|
||||
End Sub
|
||||
|
||||
@@ -159,4 +163,5 @@ Sub Service_Destroy
|
||||
End If
|
||||
Tracking = False
|
||||
lock.ReleasePartialLock
|
||||
Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Tracker - Service_Destroy', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Reference in New Issue
Block a user