-
Notifications
You must be signed in to change notification settings - Fork 72
Replace fused location provide with GPS #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
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
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.
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).
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
| try { | ||
| watcher.client.requestLocationUpdates( | ||
| LocationManager.GPS_PROVIDER, | ||
| 1000, | ||
| watcher.distanceFilter, | ||
| watcher.locationCallback | ||
| ); | ||
| } catch (SecurityException ignore) { } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ab6a04a
|
I would prefer it when the provider could be specified by the |
|
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... |
|
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. |
|
I actually find the stale location a good UX when using fused location since you can get an initial location fast but less accurate... |
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.