Skip to content

A Flutter Plugin to handle location, handling callbacks to get continuous location.

License

Notifications You must be signed in to change notification settings

BenSower/flutterlocation

 
 

Repository files navigation

Flutter Location Plugin

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

Demo App

Getting Started

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. Still no callback when permissions granted so aiming SDK 21 is safer.

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

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

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 one time call :

var currentLocation = <String, double>{};

var location = new Location();

// Platform messages may fail, so we use a try/catch PlatformException.
try {
  currentLocation = await location.getLocation;
} on PlatformException {
  currentLocation = null;
}

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

var location = new Location();

location.onLocationChanged.listen((Map<String,double> currentLocation) {
  print(currentLocation["latitude"]);
  print(currentLocation["longitude"]);
  print(currentLocation["accuracy"]);
  print(currentLocation["altitude"]);
});

If you want a one shot updated location :

var location = new Location();

Map<String,double> currentlocation = location.onLocationChanged.firstWhere((d) => d != null);

Feedback

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

About

A Flutter Plugin to handle location, handling callbacks to get continuous location.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 53.3%
  • Dart 26.1%
  • Objective-C 18.3%
  • Ruby 2.3%