Add a GPS location library to your pubspec.yaml
file and run flutter pub get
within terminal
(if it doesn’t automatically run when saving the file):
... // dependencies: (line 23)
geolocator: ^6.2.1
... // pubspec.yaml
Add the following permission to your Android Manifest file, located in <project root>/android/app/src/main/AndroidManifest.xml
:
... // <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.workshop_app">
... // (line 3)
<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" />
<uses-permission android:name="android.permission.INTERNET"/>
... // <application android:label=...
If you are using an Android Emulator please set up a fake location for this lab:
Add the following permisssion to <project root>/ios/Runner/Info.plist
:
/// ... <dict> (line 4)
<key>NSLocationAlwaysUsageDescription</key>
<string>Needed to access location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Needed to access location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>