Android Question B4A FusedLocationProvider - Location accuracy compared to Android Studio

mo_alex

Member
Licensed User
Hello, I have a concern about the accuracy of the GPS positions in Basic4Android.

The accuracy value of the position data provided by the FLP is very high. It is mostly in the four-digit range. This makes the position data almost useless.

I did a test by using two simple demo apps. One in B4A and the other in Android Studio.

Both test apps do nothing else but position updates. Both test apps use the FusedLocationProvider.

The result of the test:
The B4A app provided accuracy values between 1500 and 1900
The native app provided accuracy values between 7 and 30 (much better)

Now we are wondering what is the reason for this and how we can counteract it, because valid position data is important to our company.

Can you help us with the problem? I look forward to your feedback!

Thank you and kind regards
 
Last edited:

mo_alex

Member
Licensed User
Can you upload the B4A project?

Main:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location
Sub Process_Globals
    Private rp As RuntimePermissions
    Private StateMessage As String
End Sub

Sub Globals
    Private lblLocation As B4XView
    Private lblState As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    If StateMessage <> "" Then SetState(StateMessage)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnStart_Click
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Starter.flp.IsConnected = False Then
        SetState("Location provider not available")
    End If
    If Result Then
        Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
        Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
        Dim sc As StatusCodes
        Select SettingsResult.GetLocationSettingsStatus.GetStatusCode
            Case sc.SUCCESS
                SettingsAreGood
            Case sc.RESOLUTION_REQUIRED
                SetState("RESOLUTION_REQUIRED")
                SettingsResult.GetLocationSettingsStatus.StartResolutionDialog("srd")
                Wait For srd_ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
                If LocationSettingsUpdated Then
                    SettingsAreGood
                Else
                    SetState("Not enabled")
                End If
            Case Else
                SetState("Not available")
        End Select
    Else
        SetState("No permission")
    End If
End Sub

Sub SettingsAreGood
    SetState("Location enabled - waiting for updates")
    CallSub(Starter, "StartLocationUpdates")
End Sub


Public Sub Location_Changed (loc As Location)
'    lblLocation.Text = $"$1.2{loc.Latitude} / $1.2{loc.Longitude}"$
    lblLocation.Text = "Acc: " & loc.Accuracy & CRLF & "Valid: " & loc.AccuracyValid
    Log(" ")
    Log("==== ==== ==== ==== ====")
    Log("Acc: " & loc.Accuracy)
    Log("Valid: " & loc.AccuracyValid)
    Log("Lat: " & loc.Latitude)
    Log("Long: " & loc.Longitude)
    Log("==== ==== ==== ==== ====")
    Log(" ")
End Sub


Sub SetState (msg As String)
    StateMessage = msg
    lblState.Text = "State: " & msg
    Log(lblState.Text)
End Sub
 

Attachments

  • Starter.bas
    1.6 KB · Views: 160
  • AndroidManifest.xml
    1.3 KB · Views: 165
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is important to understand that eventually the exact same feature is used. It dosen't matter whether you call it from B4A or Android Studio. It is possible that the configuration is different.

I've created a simple example: https://www.b4x.com/android/forum/threads/fusedlocationprovider.50614/post-717726

The accuracy that I see is around 16 - 30 meters. Make sure to test it outdoors. There is no GPS reception indoors.

i_view64_haiAKUit7X.png
 
Upvote 0

mo_alex

Member
Licensed User

Attachments

  • Screenshot_20200312-153415.png
    Screenshot_20200312-153415.png
    55.7 KB · Views: 205
  • Screenshot_20200312-153449.png
    Screenshot_20200312-153449.png
    55.8 KB · Views: 196
  • Screenshot_20200312-153453.png
    Screenshot_20200312-153453.png
    55.3 KB · Views: 173
Upvote 0

mo_alex

Member
Licensed User
The many pictures are only intended to demonstrate the jumps in accuracy.

The test was done outside during good weather.

Device: Nokia 7.1
Android-Version: 10
FLP-Lib-Version: 1.31
GPS-Lib-Version: 1.20
B4A-Version: 9.80

Thank you for your feedback.
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hello, I have a concern about the accuracy of the GPS positions in Basic4Android.
The accuracy value of the position data provided by the FLP is very high. It is mostly in the four-digit range. This makes the position data almost useless.

That's interesting,
I've used both and FLP in different app for clients through B4A, in clients are more than happy with the accuracy especially as one is for tracking driver movements, and the other was for a delivery signature pad.

I usually test my location apps standing by a window indoors (I live in the UK, it's usually raining). I can honestly say that the accuracy is excellent on all my devices and you need to either test the app by a Window not surrounded by building or actually stand outside. I also use the FLP in a Smart Watch app with no issues whatsoever, it tracks my position to the front door of my house with ease.

Just make sure that you are not in a locked room with no windows o_O
 
Upvote 0

mo_alex

Member
Licensed User
The location comes directly from the OS.
Have you seen the permission dialog when you ran it?

Can you upload the Java project that you tested?

Yes, I gave the authorization when I started the app. I chose "always allow".
Regarding the Android Studio app, it's the "Location Updates" demo app, which you can open as a sample project when you start Android Studio.
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Strange! I have used FLP in one of my app which has 2500+ daily active users. It detects if a user is inside a shopping mall or not. If inside it tracks user's step count via pedometer. If you complete a predefined threshold you will get a shopping or dining discount coupon.

And it becomes very popular among the mall visitors. As per the analytic data until now the app is tracking GPS location accurately.
 
Upvote 0

mo_alex

Member
Licensed User
Change the CreateLocationRequest sub to:
B4X:
Private Sub CreateLocationRequest As LocationRequest
    Dim lr As LocationRequest
    lr.Initialize
    lr.SetInterval(10000)
    lr.SetFastestInterval(lr.GetInterval / 2)
    lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
    Return lr
End Sub

I'll try it tomorrow. Thanks for your continued help so far.
 
Upvote 0

mo_alex

Member
Licensed User
I have tested it and now I get usable values! Thanks a lot!

Is it actually possible to query the number of satellites with the FLP?
Or do I have to initialize a GPS object?
And if so, wouldn't that interfere with the FLP's location updates?

Or should I start a new thread for that question?
 
Upvote 0
Top