I have included in my flutter page a simple GoogleMap component only to see if it works but I can’t resolve this problem. I compile the application and when I navigate to the page I get the following error in the console:
“E/GoogleMapController( 3376): Cannot enable MyLocation layer as location permissions are not granted”
I can see the component but I’m not able to see the map (see the image):
Added configurations:
//(AndroidManifest.xml)
<meta-data android:name="com.google.android.geo.API_KEY" android:value="apikey"/>
//(pubspec.yaml)
google_maps_flutter: ^0.5.0
EDIT – SOLUTION
Add the permission package to request permission. You can install this package to manage your permissions: https://pub.dartlang.org/packages/permission
android.permission.ACCESS_FINE_LOCATION
is considered a dangerous permission. Have you used the permission
package to request the permission? https://pub.dartlang.org/packages/permission
Answer:
If on an emulator delete the following in your AndroidManifest file:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and keep:
<uses-permission android:name="android.permission.INTERNET"/>
This worked for me. I also closed out and rebuilt the entire app in the emulator.
Answer:
May be your API key is not setup properly and granted location service access.
Check and enable these services
Answer:
As of December 2019 I was not successful with using the permissions plugin. Even after adding the necessary manifest data and upgrading the project to Android API 29
it still returned, PermissionStatus.notAgain
.
What did work was adding the permissions_handler plugin with the manifest data they provided (just the location part). Also, upgrading the Android API to 29 as detailed here and changing the compileSDKVersion
and targetSdkVersion
in android/app/build.gradle
to 29
.
Mainfest data, just before the <application>
tag in directory android/app/src/main/AndroidManifest.xml
<!-- Permissions options for the `location` group -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Restart the IDE to make sure all those changes take effect. Then to request the permission in your app:
import 'package:permission_handler/permission_handler.dart';
void setPermissions() async{
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler().requestPermissions([PermissionGroup.location]);
}
Tags: androidandroid