Giter Club home page Giter Club logo

flutterlocation's Introduction

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 1.4 version, you have to call getLocation() instead of just getLocation and onLocationChanged() instead of onLocationChanged.

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 a one time location :

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"]);
  print(currentLocation["speed"]);
  print(currentLocation["speed_accuracy"]); // Will always be 0 on iOS
});

API

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

Methods Description
Future<Map<String, double>> getLocation()
Allow to get a one time position of the user.
Future<bool> hasPermission()
Return a boolean to know the state of the location permission.
Stream<Map<String, double>> onLocationChanged()
Get the stream of the user's location.

Feedback

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

flutterlocation's People

Contributors

lyokone avatar alexays avatar g123k avatar cameronwebbable avatar bcko avatar jharrison902 avatar fluff avatar tensafefrogs avatar jalpedersen avatar johnpryan avatar yathit avatar matthewtsmith avatar pauldemarco avatar quangio avatar vagrantrobbie avatar sethladd avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.