My code is:
class _LoadingScreenState extends State<LoadingScreen> {
void getLocation() async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low);
print(position);
}
I added to the Android manifest the following:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Android emulator, GPS is on.
After trying to access geolocation I receive an error:
E/flutter ( 5034): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: User denied permissions to access the device's location.
E/flutter ( 5034): #0 MethodChannelGeolocator.getCurrentPosition (package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:127:7)
E/flutter ( 5034): <asynchronous suspension>
E/flutter ( 5034): #1 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:11:25)
E/flutter ( 5034): <asynchronous suspension>
In Settings - Security & location - Privacy - Location - App level permissions
my app's permission is off.
After turning it on I receive a request:
Why is it happening?
Here https://pub.dev/packages/geolocator it is stated that
The geolocator will automatically try to request permissions when you try to acquire a location through the getCurrentPosition or getPositionStream methods. We do however provide methods that will allow you to manually handle requesting permissions.
Aren't the permissions supposed to be set as a result of the selection in the permission request?
I have almost the same problem with iOS: In the Settings - Privacy - Location Services - my app permission is set to While Using. After trying to access geolocations I receive to dialog window but an error:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: User denied permissions to access the device's location. #0 MethodChannelGeolocator.getCurrentPosition (package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:127:7) #1 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:11:25)
but why?