Search code examples
flutterpermissionslocationandroid-permissions

Flutter permission_handler issue


I am new to flutter and was following this guide on permission_handler.

I am running tests of my app on android 13 and when I request permissions I can also choose to grant only the approximate location and not the exact location.

When I grant the precise location permissions I have no problem.

The problem is when I grant the approximate location. When I go to check the status of Permission.location.status, Permission.locationWhenInUse.status and Permission.locationAlways.status all 3 are 'denied'.

How do I differentiate when the user is not granting permissions and when they are only granting the approximate location?

How can I check what kind of precision the user has granted me?

I tried to print out in console all permissions and all statuses but I can't find anything about the approximate location


Solution

  • Currently permission_handler does not support checking for the case when a user grants approximate location permissions.

    If you want to determine the location precision the user granted your app then one option is to identify the accuracy by requesting the devices current location via a geolocation package such as the Flutter Geolocator Plugin.

    import 'package:geolocator/geolocator.dart';
    
    final geo = Geolocator();
    final location = await geo.getCurrentPosition(); 
    
    // use the .accuracy to identify the estimated horizontal accuracy of the position in meters.
    
    print(location.accuracy);
    

    Note that if location.accuracy returns 0.0 - then it is not available on the device or there is no GPS signal.

    Aside from this, there is the LocationManager class in native Android code, you would need to write your own method in Flutter to access this.