Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

forceLocationManager = true may still default to fused location #1171

Open
jbxbergdev opened this issue Nov 9, 2022 · 4 comments
Open

forceLocationManager = true may still default to fused location #1171

jbxbergdev opened this issue Nov 9, 2022 · 4 comments
Assignees

Comments

@jbxbergdev
Copy link

jbxbergdev commented Nov 9, 2022

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.

@TimHoogstrate TimHoogstrate self-assigned this Aug 14, 2023
@mvanbeusekom
Copy link
Member

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.

@jbxbergdev
Copy link
Author

jbxbergdev commented Apr 30, 2024

@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.

@mvanbeusekom
Copy link
Member

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.

@jbxbergdev
Copy link
Author

jbxbergdev commented Mar 20, 2025

@mvanbeusekom @TimHoogstrate Could you have a look at my PR?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants