geolocation
Flutter geolocation plugin for Android API 16+ and iOS 9+.
Features:
- Manual and automatic location permission management
- Current one-shot location
- Continuous location updates with foreground and background options
The plugin is under active development and the following features are planned soon:
- Geocode
- Geofences
- Place suggestions
- Activity recognition
- Exposition of iOS/Android specific APIs (like significant location updates on iOS)
Android | iOS |
---|---|
![]() |
![]() |
Installation
Follow the instructions: https://pub.dev/packages/geolocation#-installing-tab-
Android
Geolocation is dependent on AndroidX. Make sure to include the following settings to 'android/gradle.properties':
android.useAndroidX=true
android.enableJetifier=true
Permission
Android and iOS require to declare the location permission in a configuration file.
For iOS
There are two kinds of location permission available in iOS: "when in use" and "always".
If you don't know what permission to choose for your usage, see:
https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services
You need to declare the description for the desired permission in ios/Runner/Info.plist
:
For Android
There are two kinds of location permission in Android: "coarse" and "fine".
Coarse location will allow to get approximate location based on sensors like the Wifi, while fine location returns the most accurate location using GPS (in addition to coarse).
You need to declare one of the two permissions in android/app/src/main/AndroidManifest.xml
:
Note that ACCESS_FINE_LOCATION
permission includes ACCESS_COARSE_LOCATION
.
API
For more complete documentation on all usage, check the API documentation:
https://pub.dartlang.org/documentation/geolocation/latest/geolocation/geolocation-library.html
You can also check the example project that showcase a comprehensive usage of Geolocation plugin.
Check if location service is operational
API documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/isLocationOperational.html
Request location permission
On Android (api 23+) and iOS, apps need to request location permission at runtime.
Note: You are not required to request permission manually.
Geolocation plugin will request permission automatically if it's needed, when you make a location request.
API documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/requestLocationPermission.html
Get the current one-shot location
Geolocation offers three methods:
- Last known location (best on Android):
https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/lastKnownLocation.html - Single location update (best on iOS):
https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/singleLocationUpdate.html - Current location (best of both worlds, tries to retrieve last known location on Android, otherwise requests a single location update):
https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/currentLocation.html
Continuous location updates
API documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/Geolocation/locationUpdates.html
Handle location result
Location request return either a LocationResult
future or a stream of LocationResult
.
API documentation: https://pub.dartlang.org/documentation/geolocation/latest/geolocation/LocationResult-class.html
Authors
Geolocation plugin is developed by Loup, a mobile development studio based in Montreal and Paris.
You can contact us at hello@loup.app
Contributers
- lukaspili
- mit-mit
- shehabic-work
- Abgaryan
- shehabic
- alfanhui