flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Exclusive function to Request Location Service

Open bajajsahil opened this issue 5 years ago • 8 comments

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

bajajsahil avatar Oct 10 '20 08:10 bajajsahil

Hi @mvanbeusekom, your response is appreciated. I am waiting for it.

Thanks.

bajajsahil avatar Oct 24 '20 08:10 bajajsahil

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.

mvanbeusekom avatar Oct 24 '20 08:10 mvanbeusekom

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?

bajajsahil avatar Oct 24 '20 09:10 bajajsahil

That is correct, on iOS and Android (when using LocationManager) will throw an LocationServiceDisabledException when GPS services are disabled when requesting a position.

mvanbeusekom avatar Oct 24 '20 09:10 mvanbeusekom

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

bajajsahil avatar Oct 27 '20 08:10 bajajsahil

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.

mvanbeusekom avatar Oct 27 '20 08:10 mvanbeusekom

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.

bajajsahil avatar Oct 27 '20 08:10 bajajsahil

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

lightify97 avatar Jun 28 '23 17:06 lightify97