I have a service that gets the gps location & creates a record in a db every 30mins. It is set to run at every 30mins & to start when the phone is booted.
When i run it seems to be working correctly whilst the GPS on phone is getting enough signal.
When it cant get a signal it then appears to add a record every second or two using the coordinates of the last successful connection to the gps.
How do i ensure that this does not happen?
I only want it to post a record in the database if it gets a valid signal.
The code is below & would appreciate if you could point out where i am going wrong.
When i run it seems to be working correctly whilst the GPS on phone is getting enough signal.
When it cant get a signal it then appears to add a record every second or two using the coordinates of the last successful connection to the gps.
How do i ensure that this does not happen?
I only want it to post a record in the database if it gets a valid signal.
The code is below & would appreciate if you could point out where i am going wrong.
B4X:
'Service module
Sub Process_Globals
Dim phoneInfo As PhoneId
Dim deviceID As String
deviceID = phoneInfo.GetDeviceId
Dim httpC As HttpClient
Dim GPS1 As GPS
Dim Currentloc As Location
Dim Latitude, Longitude As Double
Dim reader As TextReader
Dim count As Int
count = 0
Dim aa,bb,c As String
End Sub
Sub Service_Create
GPS1.Initialize("GPS")
Currentloc.Initialize()
httpC.Initialize("httpC")
End Sub
Sub GPS_LocationChanged (Loc As Location)
Currentloc = Loc
count = 0
count = count + 1
Longitude = Loc.Longitude
Latitude = Loc.Latitude
createRecord
GPS1.Stop
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 30 * DateTime.TicksPerMinute, False)
GPS1.Start(0, 0)
End Sub
Sub Service_Destroy
GPS1.Stop
End Sub
Sub createRecord
Dim lat, lon As Double
lon = Currentloc.Longitude
lat = Currentloc.Latitude
Dim now As Long
now = DateTime.now
DateTime.DateFormat = "dd/MM/yyyy"
Dim edtdate, edttime, edtdatetime As String
edtdate = DateTime.Date(now)
edttime= DateTime.Time(now)
aa = edtdate
bb = edttime
edtdatetime = aa &"-"& bb
c = edtdatetime
Dim req As HttpRequest
sendrequest = "http://thexspots.webege.com/netdb.php?action=addgps&lat="
req.InitializeGet(sendrequest & lat & "&lon=" & lon &"&deviceID=" & deviceID & "&reddt="& c)
httpC.Execute(req, 1)
GPS1.stop
End Sub
Sub httpC_ResponseSuccess (Response As HttpResponse, TaskId As Int)
ProgressDialogHide
End Sub