location 2.3.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 100

Flutter Location Plugin pub package

This plugin for Flutter handles getting location on Android and iOS. It also provides callbacks when location is changed.

Demo App

Breaking Changes #

As of the 2.0 version, you have to call the returned location is an LocationData Object. You can just access the different attribute like so : location.latitude. See the API part of the README for the changes. This version also switched to AndroidX instead of the old Android Support library. In order to use it you have to do the following things:

Update your gradle.properties file with this:

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M

Please also make sure that you have those dependencies in your build.gradle:

  dependencies {
      classpath 'com.android.tools.build:gradle:3.3.0'
      classpath 'com.google.gms:google-services:4.2.0'
  }
...
  compileSdkVersion 28

Getting Started #

Android #

In order to use this plugin in Android, you have to add this permission in AndroidManifest.xml :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Permission check for Android 6+ was added.

iOS #

And to use it in iOS, you have to add this permission in Info.plist :

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

Warning: there is a currently a bug in iOS simulator in which you have to manually select a Location several in order for the Simulator to actually send data. Please keep that in mind when testing in iOS simulator.

Example App #

The example app uses Google Maps Flutter Plugin, add your API Key in the AndroidManifest.xml and in AppDelegate.m to use the Google Maps plugin.

Sample Code #

Then you just have to import the package with

import 'package:location/location.dart';

Look into the example for utilisation, but a basic implementation can be done like this for a one time location :

var currentLocation = LocationData;

var location = new Location();

// Platform messages may fail, so we use a try/catch PlatformException.
try {
  currentLocation = await location.getLocation();
} on PlatformException catch (e) {
  if (e.code == 'PERMISSION_DENIED') {
    error = 'Permission denied';
  } 
  currentLocation = null;
}

You can also get continuous callbacks when your position is changing:

var location = new Location();

location.onLocationChanged().listen((LocationData currentLocation) {
  print(currentLocation.latitude);
  print(currentLocation.longitude);
});

Public Method Summary #

In this table you can find the different functions exposed by this plugin:

ReturnDescription
FuturerequestPermission()
Request the Location permission. Return a boolean to know if the permission has been granted.
FuturehasPermission()
Return a boolean to know the state of the location permission.
FutureserviceEnabled()
Return a boolean to know if the Location Service is enabled or if the user manually deactivated it.
FuturerequestService()
Show an alert dialog to request the user to activate the Location Service. On iOS, will only display an alert due to Apple Guidelines, the user having to manually go to Settings. Return a boolean to know if the Location Service has been activated (always false on iOS).
FuturechangeSettings(LocationAccuracy accuracy = LocationAccuracy.HIGH, int interval = 1000, double distanceFilter = 0)
Will change the settings of futur requests. accuracywill describe the accuracy of the request (see the LocationAccuracy object). interval will set the desired interval for active location updates, in milliseconds (only affects Android). distanceFilter set the minimum displacement between location updates in meters.
FuturegetLocation()
Allow to get a one time position of the user. It will try to request permission if not granted yet and will throw a PERMISSION_DENIED error code if permission still not granted.
StreamonLocationChanged()
Get the stream of the user's location. It will try to request permission if not granted yet and will throw a PERMISSION_DENIED error code if permission still not granted.

You should try to manage permission manually with requestPermission() to avoid error, but plugin will try handle some cases for you.

Objects #

class LocationData {
  final double latitude; // Latitude, in degrees
  final double longitude; // Longitude, in degrees
  final double accuracy; // Estimated horizontal accuracy of this location, radial, in meters
  final double altitude; // In meters above the WGS 84 reference ellipsoid
  final double speed; // In meters/second
  final double speedAccuracy; // In meters/second, always 0 on iOS
  final double heading; //Heading is the horizontal direction of travel of this device, in degrees
  final double time; //timestamp of the LocationData
}


enum LocationAccuracy { 
  POWERSAVE, // To request best accuracy possible with zero additional power consumption, 
  LOW, // To request "city" level accuracy
  BALANCED, // To request "block" level accuracy
  HIGH, // To request the most accurate locations available
  NAVIGATION // To request location for navigation usage (affect only iOS)
}

Note: you can convert the timestamp into a DateTime with: DateTime.fromMillisecondsSinceEpoch(locationData.time.toInt())

Feedback #

Please feel free to give me any feedback helping support this plugin !

[2.3.5] 10th April 2019

  • Fix incompatibily with headless plugins thanks to ehhc
  • Fix error with iOS when permission already given
  • Add Google maps example

[2.3.4] 8th April 2019

  • Fix error on Android 21 API thanks to noordawod
  • Update Google API version

[2.3.3] 31th March 2019

  • Align altitude on Sea Level when available on Android (matching iOS altitude).

[2.3.2] 27th March 2019

  • Remove GPS limitation on Android

[2.3.1] 25th March 2019

  • Fixes README
  • Fixes requestPermission not responding the correct result on iOS

[2.3.0] 22nd March 2019

  • Update example App with proper cancel
  • Add possibility to set accuracy, interval and minimum notification ditance of the requests.
  • Add LocationAccuracy object

[2.2.0] 19th March 2019

  • Actually updating locatino when using getLocation (not only relying on LastLocation)
  • Add timestamp to LocationData
  • Add serviceEnabled method to check whether Location Service is enabled.
  • Add requestService method to ask the user to activate the location service.
  • Fix continuous callback heading

[2.1.0] 16th Match 2019

  • iOS permission should be closer to Android permission behaviour thanks to PerrchicK
  • Adding requestPermission(), to manually request permission
  • Several feature fixed for less crash when using the plugin
  • Code Cleanup
  • Update Readme and add a warning for the location bug in iOS simulator

[2.0.0] 25th January 2019

  • Code cleanup
  • BREAKING CHANGE: Change Dart API to return structured data rather than a map.

[1.4.0] 21st August 2018

  • Add lazy permission request thanks to yathit
  • Add hasPermission() thanks to vagrantrobbie
  • Bug correction thanks to jalpedersen
  • Add more examples

[1.3.4] 4th June 2018

  • Fix crash for Android API pre 27 thanks to matthewtsmith.

[1.3.3] 30th May 2018

  • Correct implementation of iOS plugin to match Android behaviour. No need to call getLocation to get permissions for location callbacks.

[1.3.2] 30th May 2018

  • Change implementation to api in build.gradle in order to solve incompatibilities between GMS versions thanks to luccascorrea

[1.3.1] 29th May 2018

  • Added speed and speed_accuracy (only Android truly discover speed accuracy, so its always 0 for now on iOS)
  • Solved a crash

[1.3.0] 27th May 2018

  • Make it compatible with Firebase thanks to quangIO
  • Resolve runtime error exception thanks to jharrison902
  • Update gitignore thanks to bcko

[1.2.0] 5th April 2018

  • Permissions denied on Android handled thanks to g123k
  • Dart 2 update thanks to efortuna

[1.1.6] - 19th Octobre 2017.

  • iOS code from Swift to Objective-C thanks to fluff

[1.1.1] - 20th July 2017.

  • Fixes for iOS result's format.

[1.1.0] - 17th July 2017.

  • Added permission check for Android 6+ (thanks netdur). Still no callback when permissions granted so aiming SDK 21 is safer.

[1.0.0] - 7th July 2017.

  • Initial Release.

example/README.md

location_example #

Demonstrates how to use the location plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  location: ^2.3.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:location/location.dart';
  
Version Uploaded Documentation Archive
2.3.5 Apr 10, 2019 Go to the documentation of location 2.3.5 Download location 2.3.5 archive
2.3.4 Apr 8, 2019 Go to the documentation of location 2.3.4 Download location 2.3.4 archive
2.3.3 Mar 31, 2019 Go to the documentation of location 2.3.3 Download location 2.3.3 archive
2.3.2 Mar 27, 2019 Go to the documentation of location 2.3.2 Download location 2.3.2 archive
2.3.1 Mar 25, 2019 Go to the documentation of location 2.3.1 Download location 2.3.1 archive
2.3.0 Mar 22, 2019 Go to the documentation of location 2.3.0 Download location 2.3.0 archive
2.2.0 Mar 19, 2019 Go to the documentation of location 2.2.0 Download location 2.2.0 archive
2.1.0 Mar 16, 2019 Go to the documentation of location 2.1.0 Download location 2.1.0 archive
2.0.0 Feb 7, 2019 Go to the documentation of location 2.0.0 Download location 2.0.0 archive
1.4.1 Aug 22, 2018 Go to the documentation of location 1.4.1 Download location 1.4.1 archive

All 28 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
100
Learn more about scoring.

We analyzed this package on Apr 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8