Android Question GPS / Location Manager "troubles..."

kepler

Active Member
Licensed User
Longtime User
Good afternoon,

I need a little help here with GPS or Location Manager.

I'm trying to integrate either one of them in a service module - but I only get zero values.

Here's a piece of the code I'm using:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Timer_Location As Timer
   
    Dim VLongitude As Double = 0
    Dim VLatitude As Double = 0
    Dim Velocity As Double
    Dim lm As LocationManager

End Sub

Sub Service_Create
   
    lm.Initialize("Location")
       
    Timer_Location.Initialize("TimerLocation",30000) '60 s = 60000 ms
    Timer_Location.Enabled=True
End Sub

Sub Location_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
    VLongitude = Longitude
    VLatitude = Latitude
    ToastMessageShow(VLongitude & " / " & VLatitude,False)
End Sub

Sub Location_ProviderDisabled (Provider As String)
    'Msgbox("Provider","Provider Disabled")
End Sub

Sub Location_ProviderEnabled (Provider As String)
    'Msgbox("Provider","Provider Enabled")
End Sub

Sub Location_StatusChanged (Provider As String, Status As Int)
    'Msgbox("Provider: " & Provider & CRLF & "Status: " & Status,"Status Changed")
End Sub

Sub TimerLocation_Tick
   'Handle tick events
   lm.requestGPSLocation
   Log("Request sent...")
End Sub

Is this not working because it's running in a service module?... But neither the simple GPS is...

Help nedeed... Thanks,

Kepler
 

JTmartins

Active Member
Licensed User
Longtime User
I've only worked with standard GPS not with the location manager Lib but if you change

B4X:
Sub TimerLocation_Tick
   'Handle tick events
   lm.requestGPSLocation
   Log("Request sent...")
End Sub

to

B4X:
Sub TimerLocation_Tick
   'Handle tick events
  lm.requestMobileLocation
   Log("Request sent...")
  toastmessageshow (VLongitude & " / " & VLatitude, false)
End Sub

The requestMobileLocation should give you the location based on the 3G network (you need to be using a mobile sim card :) )

Location Changed will not probably not fire inside a house if you use GPS as the LocationChanged means that that sub will only fire when actualy there is a location change..meaning if the device is stationary...it will probably not fire that sub so values will always be zero.

So move around a few hundred meters and see what you get.

But as I've said, never used location manager before, but I presume it should't be very different from standard GPS lib.

JM
 
Last edited:
Upvote 0

kepler

Active Member
Licensed User
Longtime User
Hi Erel,

Yes, I did. I was able to get a location through Location Manager Lib, with the requestMobileLocation. Still, I had o use a "try/catch" routine since there's an error of the type "provider=network" in the emulator - I suspect the same thing could happen in a tablet.

Regards,

Kepler
 
Upvote 0
Top