flutter-geolocator
flutter-geolocator copied to clipboard
Do not force users to have Google's LocationService enabled
🐛 Bug Report
Having turned on location service with Google's location service turned off (see screenshot), I expect to be able to use the location services provided by the system, not by Google's services. Unfortunately, it seems, that we are stuck with using Google services, if they are installed with the system.
Also it would be nice, ~to have a hint in the Readme, when and how Google's service is used,~ and to manually configure whether we should force the user to use google's services.
Expected behavior
In the scenario above, I expect await Geolocator.isLocationServicesEnabled() to return true, but it returns false.
Reproduction steps
- Turn on location service,
- Turn off Google's location service,
- Run
await Geolocator.isLocationServiceEnabled().
Configuration
Version: 6.1.13
Platform:
- [ ] :iphone: iOS
- [x] :robot: Android

Edit: I noticed, that there is in fact a hint in the readme. :)
If you don't want to use the Google services you can use the forceAndroidLocationManager boolean in the methods getLastKnownPosition, getCurrentPosition and getPositionStream this will force the geolocator plugin to use the LocationManager API instead of the FusedLocationProviderClient API (which makes use of Google Services).
I will have a more detailed look on why the isLocationServiceEnabled method is returning false and if this is accurate (obviously it doesn't really match with the users expectations). A quick analysis of the code shows that it currently detects that the Google Services are available on the device (i.e. installed) but returns false because the Google Location Accuracy setting has been disabled. I need to run some more tests to see if the location is still being retrieved.
I will leave this issue open for now and will add additional test findings as soon as I find them.
As far as I can see, the most practical way (from user-perspective) would be, if we use Google's location service and if that's disabled, we use the system location service. Hence I think (from dev-perspective) it would be best, if Geolocator would have this logic built-in itself (i.e. first check whether Google's service is available; if not check whether System service is available and use the first one available) and only make it optional for the dev to select a preferred method. This is just a suggestion as this would be the behavior which I would have expected from Geolocator.
You are right and the geolocator already tries to do so, but as far as I know we can only check if Google Serivces are installed. I am not aware of a possibility to detect if the specific "Google Location Accuracy" setting has been enable or disabled making it hard to automatically switch.
Of course if can point me to resources which explain how this can be detected I would be happy to update the code.
Thanks for your fast response! I just did a quick research and maybe the following resource helps: https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient
I am not really into Android development, I just happen to use your library, so maybe you know better than me if this is the right api :)
If you use this plug-in in China, you must install Google Service (GMS). You can use TapTap to download the Google suite. If the installation is successful, you must restart your phone, and then remember to put the VPN location and flutter-geolocator on your phone. It’s no problem if you don’t have GMS. The plug-in will always hang without returning
I can't receive location updates from getPositionStream with Google Location Accuracy turned off, even if forceLocationManager is true.
geolocator: ^9.0.2
- forceLocationManager true, Google Services on and Google Location Accuracy off: I don't receive any updates.
- forceLocationManager false, Google Services on and Google Location Accuracy off:
E/flutter (31117): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: The location service on the device is disabled.
E/flutter (31117): #0 GeolocatorAndroid.getPositionStream.<anonymous closure> (package:geolocator_android/src/geolocator_android.dart:187:9)
I can't receive location updates from getPositionStream with Google Location Accuracy turned off, even if
forceLocationManageris true.geolocator: ^9.0.2
- forceLocationManager true, Google Services on and Google Location Accuracy off: I don't receive any updates.
- forceLocationManager false, Google Services on and Google Location Accuracy off:
E/flutter (31117): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: The location service on the device is disabled. E/flutter (31117): #0 GeolocatorAndroid.getPositionStream.<anonymous closure> (package:geolocator_android/src/geolocator_android.dart:187:9)
same issue, When I set the forceLocationManager value to true, the data comes too late. (sometimes it doesn't come at all).
Using the Location plugin has the same problem. When you try to get the position with Location Service ON but Google Location Service (Accuracy) OFF, the position is never received and the apps stuck. I don't know if will be some location plugin that resolve this problem.