Search code examples
flutterpermissionsgpslocation

how to turn on gps automatically in flutter when using geolocation


I am trying to get my current position using Geolocator package, but after pop up dialog shows to ask permission of my location and I click allow... my gps stills turn off and I have to turn it on manually, is there something that I should add in my code?

Position _mine;
   _myPosition() {
    final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;

    geolocator
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
        .then((Position position) {
      setState(() {
        _mine = position;
      });
      print(_mine.latitude);
    }).catchError((err) {

    });
  }

Solution

  • if you want to forcefully turn your device GPS your can use access_settings_menu package and use 'ACTION_LOCATION_SOURCE_SETTINGS' as the settings name