Skip to content

Conversation

@HarelM
Copy link
Contributor

@HarelM HarelM commented Jul 23, 2025

This replaces the fused location provider with the GPS.
To be honest, google does advise to use the fused location provider, I just found it problematic in some rare cases.

This PR swaps out completely the fused location provider, but I can complicate it to allow both (there will be a need for a small watcher interface and some small implementation for each provider, nothing too complicated but still.

Let me know how you want to proceed.

Note that this is a breaking change in terms of the plugin behavior.

@HarelM
Copy link
Contributor Author

HarelM commented Jul 23, 2025

Here's ChatGPT version of when you should not use fused location (I removed some non relevant sections):

The Fused Location Provider API (FLP) in Android is the preferred way to get location because it balances accuracy and battery usage by using a combination of GPS, Wi-Fi, and cellular networks. However, there are specific scenarios when you should not use FLP or consider alternatives:


🚫 When Not to Use Fused Location Provider


  1. High-Accuracy Requirements in Isolated Areas

Why: FLP may fall back on Wi-Fi or cell tower triangulation, which is inaccurate in rural or GPS-deprived areas.

Alternative: Use LocationManager directly with GPS_PROVIDER for precise GPS-only data.


  1. Real-Time Tracking with Precise Timing

Why: FLP batches results and optimizes battery, which introduces some delay or smoothing.

Alternative: Use raw GPS via LocationManager for real-time updates (e.g., sports tracking, navigation).


  1. Device Without Google Play Services

Why: FLP is part of Google Play Services, which is not available on all devices (e.g., Huawei, AOSP-only devices).

Alternative: Use android.location.LocationManager, which is part of the Android SDK and works without Google dependencies.

LocationRequest locationRequest = new LocationRequest();
locationRequest.setMaxWaitTime(1000);
locationRequest.setInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it the GPS provider is high accuracy by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Comment on lines 145 to 152
try {
watcher.client.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
1000,
watcher.distanceFilter,
watcher.locationCallback
);
} catch (SecurityException ignore) { }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated from earlier, can it be extracted as a helper method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ab6a04a

@matthiasschwarz
Copy link
Contributor

I would prefer it when the provider could be specified by the WatcherOptions. As default should the Fused Location Provider be used.

@HarelM
Copy link
Contributor Author

HarelM commented Jul 26, 2025

I'm good with either way, I'm not sure it should be in the watcheroptions though because it's android specific, so I thought about using the strings.xml for that, but I'm good with either approach...

@diachedelic
Copy link
Collaborator

We can build in the flexibility to choose between Fused and GPS providers down the track. It's not pretty because they're configured in different ways.

There are still some references to the Fused provider in BackgroundGeolocation.java and build.gradle (just search "com.google.android.gms"). It would be nice to remove the dependency on Google Play services.

@HarelM
Copy link
Contributor Author

HarelM commented Jul 31, 2025

I actually find the stale location a good UX when using fused location since you can get an initial location fast but less accurate...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Allow selecting between GPS provider and fused location

3 participants