Problem with GPS behavior

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

The service run every 3 minutes and :
- Store a position OR
- Store a "blank position" if GPS is disabled OR
- Do NOT store data if no signal (I wish to store a "NO signal" but this is another story)

I do not understand :BangHead: why store several records in few seconds. (11,12,13)

Any idea is wellcome.

Thanks for your time

Regards

Edgar

B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim GPS1 As GPS
   Dim GPS_Str_Next_Start   As String
End Sub
Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
   Dim lc_Current_Hour   As Int
   Dim lc_Next_Start   As Long
   '
   ' StartServiceAt("", DateTime.Now + 3 * DateTime.TicksPerMinute, False)
   lc_Next_Start      = DateTime.Now + Main.SysGPSRutaTiempo * DateTime.TicksPerMinute
   lc_Current_Hour      = DateTime.GetHour(DateTime.Now)
   GPS_Str_Next_Start   = Rutinas.Get_Format_Date(lc_Next_Start, Main.SysFomatoFecha)
   '
   If Main.SysGPSRuta = "S" Then
      If lc_Current_Hour >= Main.SysGPSHoraInicio AND lc_Current_Hour <= Main.SysGPSHoraFinal Then
         ' 
         ' Cancel previos schedule (if exists)
         CancelScheduledService("")
         ' schedule the next run in "N" minutes
         '
         StartServiceAt("", lc_Next_Start, True)         
      End If
   End If
   '
   Find_GPS_Data
   '
End Sub

Sub Service_Destroy
   GPS1.Stop
   '
End Sub

Sub Find_GPS_Data
   Dim Notification_Tel As Notification
   ' 
   GPS1.Initialize("GPS")
   '
   If GPS1.GPSEnabled = False Then
      Main.GlbGPSEstado   = "I"
      Main.GlbGPSLatitud   = ""
      Main.GlbGPSLongitud   = ""
      '
      ' Mandar mensaje de activar el GPS
      Notification_Tel.Initialize
      Notification_Tel.Icon      = "icon"
      Notification_Tel.SetInfo("GPS Desactivado", "Debe de activar el GPS", "") 
      Notification_Tel.AutoCancel   = True
      Notification_Tel.Notify(1)
      '
      Store_In_Data_Base
   Else
      Main.GlbGPSEstado   = "A"
      GPS1.Start( 0, 0) 'Listen to GPS with no filters.
      ' GPS1.Start (Main.SysGPSRutaTiempo * 900, 0)
   End If
   '
End Sub

Sub GPS_LocationChanged (Location1 As Location)
   '
   Main.GlbGPSLatitud   = Location1.Latitude
   Main.GlbGPSLongitud   = Location1.Longitude
   '
   GPS1.Stop
   Store_In_Data_Base
   '
End Sub

Sub Store_In_Data_Base
   '
   Dim lcSqlComando As String
   '
   lcSqlComando = "INSERT INTO sg_t_gps (fecha_hora, latitud, longitud, estado_gps, fecha_hora_envio) values (" & _
                        "^" & Rutinas.Get_Format_Date(DateTime.Now, Main.SysFomatoFecha) & "^, " & _
                        "^" & Main.GlbGPSLatitud & "^, " & _
                        "^" & Main.GlbGPSLongitud & "^, " & _
                        "^" & Main.GlbGPSEstado & "^, " & _
                        "^" & GPS_Str_Next_Start & "^)"
   lcSqlComando   = lcSqlComando.Replace("^", Main.GlbComillas)
   Main.DBFacturacion.ExecNonQuery(lcSqlComando)
   '
   Main.GlbGPSFecha   = DateTime.Now
   StopService("")
End Sub

Data Stored:

HTML:
pk   fecha_hora             latitud                   longitud      estado_gps   pk_envio fecha_hora_envio
1   2012-10-14 17:42:54   16.929003215958836   -89.89096338709649   A   0   2012-10-14 17:45:31
2   2012-10-14 17:45:57   16.928502665532783   -89.8912513367717   A   0   2012-10-14 17:48:31
3   2012-10-14 17:48:50   16.928519248129742   -89.89052323971778   A   0   2012-10-14 17:51:31
4   2012-10-14 17:51:46   16.928698115076436   -89.89103929690377   A   0   2012-10-14 17:54:31
5   2012-10-14 17:54:40   16.92911562127           -89.89123584115553   A   0   2012-10-14 17:57:31
6   2012-10-14 17:57:43   16.929096193262932   -89.89245767218883   A   0   2012-10-14 18:00:31
7   2012-10-14 18:29:08   16.929029001273882   -89.89197426262689   A   0   2012-10-14 18:32:00
8   2012-10-14 18:47:00                                         I   0   2012-10-14 18:50:00
9   2012-10-14 20:03:54                                         I   0   2012-10-14 20:06:54
10   2012-10-14 20:06:56                                         I   0   2012-10-14 20:09:54
11   2012-10-14 20:16:11   16.92868991600736   -89.89216983174887   A   0   2012-10-14 20:18:54
12   2012-10-14 20:16:12   16.92868991600736   -89.89216983174887   A   0   2012-10-14 20:18:54
13   2012-10-14 20:16:12   16.92868991600736   -89.89216983174887   A   0   2012-10-14 20:18:54
 
Top