flutter-geolocator
flutter-geolocator copied to clipboard
[Question]: Windows 11 PlatformException when calling checkPermission method
Please check the following before submitting a new issue.
- [X] I have searched the existing issues.
- [X] I have carefully read the documentation.
Please select for which platform(s) you need help
- [ ] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [X] Windows
Your question
hello, I'm running a flutter app on Windows 11 and keep encountering the error when calling Geolocation.checkPermission()
PlatformException (PlatformException(UNKNOWN_ERROR, RequestAccess failed. Check the Geolocation Service is running., null, null))
I have enabled Location Services on my local Windows 11 machine and allowed desktop apps to access my location. Is there some configuration I need to add to my flutter app or another Windows 11 setting I need to enable?
Here is my code for reference:
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
try {
Position position = await Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.bestForNavigation));
List<Placemark> placemarks =
await placemarkFromCoordinates(position.latitude, position.longitude);
// Process placemarks as needed
return placemarks.first.locality ?? 'Unknown location';
} catch (e) {
print('Error: $e');
throw Exception('Failed to get location');
}
Version
13.0.1