By using simple_permissions and location package of Dart, it is only asking for user permission to ALLOW or DENY the app to use device location to show the current location of user on Google Maps. When i turn on the GPS manually on my device, I'm able to get the current location, but how can I ask the user to enable GPS from the app itself with a dialog to enable the GPS like Google Maps?
you can user location library
var location = Location();
Future checkGps() async {
if (!await location.serviceEnabled()) {
location.requestService();
}
}
If you already have geolocator or if you are using the two (geolocator and location packages), then first import one of them as an alias, for example for location, import it as:
import 'package:location/location.dart' as loc;
loc.Location location = loc.Location();//explicit reference to the Location class
Future _checkGps() async {
if (!await location.serviceEnabled()) {
location.requestService();
}
}
Notice that use of var location = Location() or var location = loc.Location() wont work, you have to reference the Location class exclusively with the alias loc for the example above.
Then call the method in the initState as below to be checked every once the app starts as below:
@Override
void initState()
{
super.initState();//comes first for initState();
_checkGPS();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With