Android Question Problems with Fused Location

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I am having a strange problem with Fused Location.
In my App, I have a service that every few seconds retrieves the coordinates from the fusedlocation
Every once in a while, specially in one costumer, the coordinates seem to freeze and even if the user retrieves the coordinates in two different locations, the service returns the coords for the first location.
Only by entering google maps in the same device, the fusedlocation service "unlocks"
Any idea how to solve this, other than asking the user to open google maps ?

Thanks in advance
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
FLP is a mature library/SDK. It is probably a mistake in your code.
The strangest thing is when I switch to google maps, press my location icon and then switch back to my App, the coordinates "unfreeze" and return the actual ones. Also "Unfreezes" when I show a map (mapfragment method) in the App, and then retrieve the data from FLP.
 
Last edited:
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
my Service (LocationService) with FLP
Anything wrong with it, that may be causing the reported issue ?

I call it from several parts in the APP using :

B4X:
Private sACLALatitude As String = LocationService.GeoLocal.lat
Private sACLALongitude As String = LocationService.GeoLocal.lon

GeoData is a custom type
B4X:
Type GeoData(lat As String, lon As String, date As String)

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public flp As FusedLocationProvider
    Public GeoLocal As GeoData
    Private LastLocation As Location
    Private inactivity_overpass As Boolean = False
End Sub

Sub Service_Create
    flp.Initialize("flp")
    flp.Connect
End Sub

Sub flp_ConnectionSuccess
    'Log("Connected to location provider")
'    Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
    Dim rs As ResumableSub = CheckLocationSettingStatus
    Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
 
    Dim sc As StatusCodes
    If (SettingsResult.GetLocationSettingsStatus.GetStatusCode = sc.SUCCESS) Then
        StartLocationUpdates
    End If
 
End Sub

Sub flp_ConnectionFailed(ConnectionResult1 As Int)
    'Log("Failed to connect to location provider")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub CheckLocationSettingStatus As ResumableSub
    Dim f As LocationSettingsRequestBuilder
    f.Initialize
    f.AddLocationRequest(CreateLocationRequest)
    flp.CheckLocationSettings(f.Build)
    Wait For flp_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
    Return LocationSettingsResult1
End Sub

Public Sub StartLocationUpdates
    flp.RequestLocationUpdates(CreateLocationRequest)
End Sub

Private Sub flp_LocationChanged (Location1 As Location)
    If (Utils.NNE(Location1.Latitude) And Utils.NNE(Location1.Longitude)) Then
        LastLocation=Location1
    End If
 
    UpdateUI(Location1)
End Sub

Private Sub CreateLocationRequest As LocationRequest
    Dim lr As LocationRequest
    lr.Initialize
    lr.SetInterval(0)
    lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
    lr.SetSmallestDisplacement(1)
    Return lr
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy
    flp.Disconnect
    Service.StopAutomaticForeground
End Sub


Sub UpdateUI(Location1 As Location)
    GeoLocal = Types.setGeoDataDT("-", "-", "")
    If Not(Starter.APP_RESET_INSTALL) Then
        DateTime.TimeFormat = "HH:mm:ss"
        DateTime.DateFormat = "yyyy-MM-dd"
        Dim Data As String  = $"$date{DateTime.Now} $time{DateTime.Now}"$ ' ${LastLocation.Time}"$
        Dim lat As String = "-"
        Dim lon As String = "-"
        Try
            Dim lat As String = $"${Utils.IfNullOrEmpty(Location1.Latitude, "")}"$
            Dim lon As String = $"${Utils.IfNullOrEmpty(Location1.Longitude, "")}"$
        Catch
            Log(LastException)
            Dim lat As String = ""
            Dim lon As String = ""
        End Try
        GeoLocal = Types.setGeoDataDT(lat, lon, Data)
    End If
'    ToastMessageShow($"LOCL:: Latitude: ${Utils.IfNullOrEmpty(Location1.Latitude, "")}, Logitude: ${Utils.IfNullOrEmpty(Location1.Longitude, "")}"$, False)
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…