Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve this "Cannot enable MyLocation layer as location permissions are not granted"?

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):

googleMap example flutter

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

like image 493
juan_marti Avatar asked Apr 03 '19 17:04

juan_marti


People also ask

How do I set location permissions on Android?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


2 Answers

May be your API key is not setup properly and granted location service access.

Check and enable these services

enter image description here

like image 121
Wasim Avatar answered Oct 10 '22 11:10

Wasim


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]);
}
like image 22
S.Ramjit Avatar answered Oct 10 '22 09:10

S.Ramjit