flutter-geolocator
flutter-geolocator copied to clipboard
Exclusive function to Request Location Service
💬 Questions and Help
Thanks for the new updates.
I have a question though, currently when we call "getCurrentPosition", only then pop-up is displayed to turn on the GPS(if GPS is off). Is there a way to call the request location service manually rather than directly calling the current position?
Also, the timeout should be for only retrieving user location, not for the complete request process.
Current Timeout - Request Location + Request Permssion + Retrieve Location
Expected Timeout - Retrieve Location
Please clarify this.
Appreciate your response.
Hi @mvanbeusekom, your response is appreciated. I am waiting for it.
Thanks.
Hi @bajajsahil, I have been thinking about this feature but not sure if I want to fit it into the plugin. The problem is that this feature would only work when using the Android FusedLocationProviderClient, which means it will not work for Android LocationManager nor on iOS.
In general we could maybe find some way to return an error or simply ignore the calls when run on Android LocationManager or on iOS but both are not really user friendly solutions.
Thanks, @mvanbeusekom for your response.
So, in the current implementation, if we call the getCurrentPosition on Android LocationManager or on iOS CLLocationManager, then GPS popup will not come?
That is correct, on iOS and Android (when using LocationManager) will throw an LocationServiceDisabledException when GPS services are disabled when requesting a position.
@mvanbeusekom So, It would be better to have this exclusive method I think. We should not execute our business logic until we have location services "ON" and getCurrentPosition is part of business functionality.
As you said, LocationServiceDisabledException will be thrown in the case of LocationManager and this will be perfectly fine in case of an exclusive method. A developer can handle this gracefully and can ask user to turn on the GPS manually.
That's my suggestion.
I am not against it, but it needs to be well documented and should be clear to users that this only works for Android devices which support Google Play Services (the FusedLocationProviderClient is part of the Google Play Services).
How would you suggest we handle this case on other platforms (i.e. iOS and Android LocationManager)? My suggestion would think we throw a not supported exception or something similar indicating this method doesn't work for these platforms (of course the exception message should clearly mention this) and return a boolean when running on Android with Google Play Services indicating if the activation of the location services was successful or not.
Yes, not supported exception is a good idea to differentiate between disabled and not supported error. And, boolean will be useful in case of successful execution. I completely agree with all your points.
Thanks.
@mvanbeusekom I needed the same functionality in my app, i.e. manually requesting user to enable location services. The entire workflow of the app depends on it. Couldn't find anything in geolocator. So I switched to location package which provides this functionality.