Android Question On Demand GPS in Service Module

Noorul HAQUE

Member
Licensed User
Dear All

I am just preparing one app, my requirement is, I will install this app in many devices, and read the current GSM Cell ID, latitude and longitude of these devices when ever I need. I used firebase messaging to send request for reading my required values. I used B4J to create my desktop app for sending request, I managed to create GSM part, its working fine. my problem is am not able to get GPS latitude and longitude.

I have below code, it seems to be it is not running LocationChanged part. Expecting your valued support.

in FirebaseMessaging Service Module

B4X:
Sub Process_Globals
    Private fm As FirebaseMessaging
    Dim n As Notification
    Public stpass1 As String
    Public sf As StringFunctions
    Public GPS1 As GPS
 End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    If Message.GetData == Null Or Message.GetData.Get("title") == Null Then
        Return
    End If
    If Message.GetData.Get("title")="1" Then ' Message 1 for GSM
       Dim Obj1 As Reflector
        Dim cid, lac As Int
        Dim ans As String
        Obj1.Target = Obj1.GetContext
        Obj1.Target = Obj1.RunMethod2("getSystemService", "phone", "java.lang.String")
        Obj1.Target = Obj1.RunMethod("getCellLocation") ' get a GsmCellLocation
        cid = Obj1.RunMethod("getCid") ' gsm cell id
        lac = Obj1.RunMethod("getLac") ' gsm location area code
        ans ="GSM Cell ID  " & cid & " GSM Area  " & lac
         log(ans)      '  I have code for sending to my webserver 
  End if

 If Message.GetData.Get("title")="2" Then  ' Message   2 for GPS
        GPS1.Initialize("GPS")
        GPS1.Start(0, 0)
 End If
End Sub

Public Sub LocationChanged(Location1 As Location)
    Private  ans  As String
     ans = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    ans = ans & "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    Log(ans)                  '  I have code for sending to my webserver 
     GPS1.Stop
End Sub
 

Noorul HAQUE

Member
Licensed User
Thanks Mr. Erel....

Its worked !! ..... One more small thing... how I can make maximum accuracy of GPS. I need to make sure maximum correct location before I send to my server,.

With Regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…