'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 SQL As SQL
Dim gps1 As GPS
Dim pid As PhoneId
Dim domainName As String
Dim servicePath As String
Dim serviceName As String
Dim StrUtils As StringUtils
End Sub
Sub Service_Create
Dim s As String
s=DBUtils.CopyDBFromAssets("gpsdb.db")
SQL.Initialize(s,"gpsdb.db",False)
gps1.Initialize("GPS")
domainName = "192.168.7.5:9022"
httpUtils.CallbackActivity="GPSService"
httpUtils.CallbackJobDoneSub="JobDone"
httpUtils.CallbackUrlDoneSub="UrlDone"
' domainName = manager.GetString("key1")
servicePath = "/datasnap/rest/TService/"
serviceName = "http://"&domainName&servicePath
End Sub
Sub Service_Start (StartingIntent As Intent)
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(1000*60, 0) '参数1:间隔的毫秒,参数2:间隔的米
End If
End Sub
Sub Service_Destroy
gps1.Stop
Log("GPS Stop")
End Sub
Sub GPS_LocationChanged (Location1 As Location)
Log("Latiitude="&Location1.Latitude)
Log("Longitude="&Location1.Longitude)
Log("Time="&Location1.Time)
Log( "Speed = " & Location1.Speed)
Log("Now="&DateTime.Now)
Log("IMSI="&pid.GetSubscriberId)
Dim ListOfMaps As List
ListOfMaps.Initialize
'Dim id As Int
Dim m As Map
m.Initialize
m.Put("Long", Location1.Longitude)
m.Put("Lat", Location1.Latitude)
m.Put("GetTime",DateTime.Now)
m.Put("IMSI",pid.GetSubscriberId)
ListOfMaps.Add(m)
DBUtils.InsertMaps(SQL, "gpsInfo", ListOfMaps)
Dim s As String
DateTime.DateFormat = "yyyy-MM-dd"
s = serviceName&"getMapPosition/"&StrUtils.EncodeUrl(Location1.Longitude, "UTF8")&"/"&StrUtils.EncodeUrl(Location1.Latitude, "UTF8")&"/"&StrUtils.EncodeUrl(DateTime.Date(DateTime.Now), "UTF8")&"/"&StrUtils.EncodeUrl(pid.GetSubscriberId, "UTF8")
httpUtils.PostString(s, s, ListOfMaps)
End Sub
Sub JobDone(Job As String)
Dim s As String
If HttpUtils.IsSuccess(job) Then
s = httpUtils.GetString(job)
Log(s)
End If
End Sub
Sub UrlDone(Url As String)
Log(Url & "done")
End Sub