flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

forceLocationManager = true may still default to fused location

Open jbxbergdev opened this issue 3 years ago • 4 comments

When setting forceLocationManager: true in AndroidSettings, geolocator may still request fused location provider.

The reason: LocationManagerClient calls LocationManager.getBestProvider() in order to get an appropriate location provider. This method may return LocationManager.FUSED_PROVIDER on certain devices (in my case Samsung A13, Android 12).

There should be a way to force usage of LocationManager.GPS_PROVIDER if network location is not desired. Suggestion: Don't call LocationManager.getBestProvider(), but always use LocationManager.GPS_PROVIDER, when forceLocationManager is set to true.

jbxbergdev avatar Nov 09 '22 16:11 jbxbergdev

Hi @jbxbergdev ,

Thank you for filing this issue and putting some time and trust into this plugin. Unfortunately I think you are a misguided by the naming of the different providers and classes.

The LocationManager.FUSED_PROVIDER (introduces in Android API 31) only relies on the LocationManager and has no relation with Google Play Services. Specifying the LocationManager.FUSED_PROVIDER will instruct Android (or the LocationManager class) to combine all other available providers to get to the most optimal (battery consumption vs. accuracy) location result.

Personally (I am unable to find information to back this up) I think the LocationManager.FUSED_PROVIDER is introduced to meet all those users that cannot use Google Play Services (e.g. in countries where it is disabled or forbidden) and still provide similar benefits.

The FusedLocationProviderClient comes with Google Play Services but relies on the LocationManager API. The implementation however (before LocationManager.FUSED_PROVIDER was introduced) had significant benefits on the power consumption of the device. It also added additional features, such as auto resolution when the location services are disabled (this is not supported by the LocationManager class.

I will close this issue for now, as I truly feel the current solution is correct. However I am open for more feedback since the Android documentation is not very clear on the differences.

mvanbeusekom avatar Aug 15 '23 08:08 mvanbeusekom

@mvanbeusekom the motivation behind my request was actually not the relation to Google Play services, but that my app needs to use location strictly from GNSS. Fused location also takes wifi and cellular networks into consideration. I don't want that. So, it should be possible to force usage of GPS_PROVIDER.

We used to use a fork of your repo, I'd be happy to submit a PR.

jbxbergdev avatar Apr 30 '24 15:04 jbxbergdev

Hi @jbxbergdev,

That makes sense, however in that case I would prefer an option where the user can specify an explicit provider and not always use the LocationManager.GPS_PROVIDER just because the forceLocationManager == true.

Maybe we can add optional additional parameters to the AndroidSettings class allowing overriding the provider in case the forceLocationManager is set to true. If no parameters are supplied the geolocator works as it works now (using getBestProvider().

If you could submit a PR that would be great.

mvanbeusekom avatar Apr 30 '24 15:04 mvanbeusekom