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

Geolocator doesn't work on windows and MacOs

Open RawadZogheib opened this issue 2 years ago • 1 comments

🐛 Bug Report

Code:

Future<Position> determinePosition() async {
    bool serviceEnabled;
    LocationPermission permission;

    // Test if location services are enabled.
    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      // Location services are not enabled don't continue
      // accessing the position and request users of the
      // App to enable the location services.
      return Future.error('Location services are disabled.');
    }

    permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission == LocationPermission.denied) {
        // Permissions are denied, next time you could try
        // requesting permissions again (this is also where
        // Android's shouldShowRequestPermissionRationale
        // returned true. According to Android guidelines
        // your App should show an explanatory UI now.
        return Future.error('Location permissions are denied');
      }
    }

    if (permission == LocationPermission.deniedForever) {
      // Permissions are denied forever, handle appropriately.
      return Future.error(
          'Location permissions are permanently denied, we cannot request permissions.');
    }

    // When we reach here, permissions are granted and we can
    // continue accessing the position of the device.
    return await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
}

It return "Location permissions are denied" on both (I've add the required permission on MacOs as demanded in the Readme)

Platform:

  • [ ] :MacOs
  • [ ] :Windows

RawadZogheib avatar Jul 06 '22 07:07 RawadZogheib

Same here, always returns denied even when service is enabled. No permissions requested in UI, just "denied", on macOS.

ScottWallace avatar Aug 05 '22 19:08 ScottWallace

Same for me. await Geolocator.requestPermission() shows dialog, but even if I allow, then I have denied exception.

DmitrySikorsky avatar Nov 05 '22 11:11 DmitrySikorsky

Any news on this? I am also facing this issue

DirtyNative avatar Mar 11 '23 20:03 DirtyNative

Facing same problem here

zqin97 avatar Mar 14 '23 08:03 zqin97

Same problem here

mengxiangjian13 avatar Apr 24 '23 08:04 mengxiangjian13

Same problem for me! it doesn't launch the Permission Request dialog for Windows 10.

UdaraAlwis avatar Jun 07 '23 12:06 UdaraAlwis

Same problem here, Windows. Doesn't launch permission request dialog, just returns "denied".

sarabura avatar Aug 28 '23 22:08 sarabura

On Windows the permission dialog is only shown once for an application. When the user denies permissions, the dialog is not displayed anymore when requesting permissions.

On Windows 11 this behaviour is even more irregular, since applications that are not designed for Microsoft Store are considered "Windows Desktop application" which are all bundled together and share the same permission settings.

Unfortunately I was not able to find a way on Windows to reliably determine if permissions have been denied before and return a PermantlyDenied status.

The suggested solution (coming from Microsoft) is to always requestPermission and act based on the result:

  1. If the result is denied redirect the user to the Windows settings.
  2. If the result is granted you are free to use the location services.

If anyone has a better solution feel free to leave a comment. I would love to consider alternatives. However for now I will close this issue as I see no other option to better resolve this.

mvanbeusekom avatar Oct 20 '23 10:10 mvanbeusekom