Reputation: 1747
my Flutter code :
onPressed: () async {
Geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
.then((Position position) {
setState(() {
_currentPosition = position;
print ( "LAT: ${_currentPosition.latitude}, LNG: ${_currentPosition.longitude}");
});
}).catchError((e) {
print(e);
});
},
it show the following :
`No location permissions are defined in the manifest. Make sure at least CCESS_FINE_LOCATION` or ACCESS_COARSE_LOCATION are defined in the manifest.
even thought I have added the permission in the manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.agent">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:label="agent"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
and I have the following errors that I cannot fix :
Attribute android:icon is not allowed here Unresolved class 'MainActivity'
Upvotes: 1
Views: 4698
Reputation: 2098
Add this lines inside
android->app->src->main->AndroidManifest.xml
android->app->src->profile->AndroidManifest.xml
android->app->src->debug->AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Recommended for Android 9 (API level 28) and lower. -->
<!-- Required for Android 10 (API level 29) and higher. -->
<service
android:name="MyNavigationService"
android:foregroundServiceType="location" ... >
<!-- Any inner elements would go here. -->
</service>
Upvotes: 1
Reputation: 1404
I add some information below to the @OmarMohamoud's answer.
You can check the geolocator package docs. It talks about main 2 points
If you are in Android +10 and "if you want to continue receiving updates even when your App is running in the background" according to the docs, you have to add this permission:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Check carefully the docs.
Upvotes: 1
Reputation: 3067
desiredAccuracy: LocationAccuracy.best needs both
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Upvotes: 5
Reputation: 17597
Firstly, try gradle sync
. As is suggested here:
- Sync gradle from android studio (must required step)
- flutter clean
- flutter pub get
- flutter run
Secondly, if it still does not work, it may be caused by this. To solve this, please use permission_handler package to request the Permission.location or other similar permissions, before you actually use your geo plugin.
Upvotes: 1