Android Question FusedLocationProvider -> Prevent location updates when the device has not been moved

mo_alex

Member
Licensed User
Hello, everyone! I have a problem that I can't solve and maybe someone here has an idea how to solve it.

Locating with the FusedLocationProvider works quite well when you are outdoors with a vehicle. My problem occurs when the device is not moved. Either when the vehicle has been parked, or when the device is inside a building and is not moved. In both cases I would like the "LocationChanged"-event of the FusedLocationProvider not to be triggered if I had set 50 meters as the minimum distance for a location update.

However, this is not the case. Even with a set minimum distance of 50 meters a "LocationChanged"-event is triggered although the device was not moved. I suspect this is because the FLP uses the positions of surrounding WiFi access points. These access points could be more than 50 meters away and therefore the condition for a "LocationChanged"-event would be fulfilled.

This leads to unwanted effects like "star formation" on the map.

My first idea was to discard location updates that do not have GPS as provider. However, it seems to be impossible to determine the provider of an FLP position, so my problem remains. Well, maybe someone here has another approach that could help me. Thanks in advance.
 

udg

Expert
Licensed User
Longtime User
Can't you just disreagard readings if they're identical to the last one? Or even in a short distance from it?
I mean, FLP gives you tons of readings but you record just what you need.
 
Last edited:
Upvote 0

mo_alex

Member
Licensed User
Can't you just disreagard readings if they're identical to the last one? Or even in a short distance from it?
I mean, FLP gives you tons of readings but you record just what you need.

I am already trying to do this with the method: SetSmallestDisplacement

But I suspect that the access points are more than 50 meters apart. So there are different coordinates and also the distance between these coordinates would be big enough to be registered as a new position.
 
Last edited:
Upvote 0

swChef

Active Member
Licensed User
Longtime User
As udg wrote, just disregard the surrounding noisy report data, meaning location reports closer than your threshold.
I modified flp_LocationChanged as follows, and supply a Resolution of 1E-5, 1E-4, 1E-3 etc as appropriate. You can just supply a distance (in meters), instead of what I used (Resolution*111,000 meters (which is 1 degree Lat)). Retain the new Location only if it is over the distance threshold.

B4X:
Private Sub flp_LocationChanged (Location1 As Location)
    If Location1.DistanceTo(LastNotifiedLocation)>= (Resolution*111000) Then
    CallSub2(Main, "Location_Changed", Location1)
    LastNotifiedLocation = Location1
    End If
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…