location 1.1.7

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

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 !

[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/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Map<String,double> _currentLocation;
  StreamSubscription<Map<String,double>> _locationSubscription;
  Location _location = new Location();

  bool currentWidget = true;

  Image image1;
  Image image2;


  @override
  initState() {
    super.initState();
    initPlatformState();
    _locationSubscription =
        _location.onLocationChanged.listen((Map<String,double> result) {
          setState(() {
            _currentLocation = result;
          });
        });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  initPlatformState() async {
    Map<String,double> location;
    // Platform messages may fail, so we use a try/catch PlatformException.


    try {
      location = await _location.getLocation;
    } on PlatformException {
      location = null;
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted)
      return;

    setState(() {
      _currentLocation = location;
    });
  }

  @override
  Widget build(BuildContext context) {
    if(currentWidget){
      image1 = new Image.network("https://maps.googleapis.com/maps/api/staticmap?center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}&zoom=18&size=640x400&key=YOUR_API_KEY");
      currentWidget = !currentWidget;
    }else{
      image2 = new Image.network("https://maps.googleapis.com/maps/api/staticmap?center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}&zoom=18&size=640x400&key=YOUR_API_KEY");
      currentWidget = !currentWidget;
    }

    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body:
           new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              new Stack(
                children: <Widget>[image1, image2]),
              new Center(child:new Text('$_currentLocation\n')),
            ],
          )
        )
    );
  }
}

1. Depend on it

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


dependencies:
  location: "^1.1.7"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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
1.1.7 Nov 29, 2017 Go to the documentation of location 1.1.7 Download location 1.1.7 archive
1.1.6 Oct 19, 2017 Go to the documentation of location 1.1.6 Download location 1.1.6 archive
1.1.5 Oct 15, 2017 Go to the documentation of location 1.1.5 Download location 1.1.5 archive
1.1.4 Sep 12, 2017 Go to the documentation of location 1.1.4 Download location 1.1.4 archive
1.1.3 Jul 20, 2017 Go to the documentation of location 1.1.3 Download location 1.1.3 archive
1.1.2 Jul 20, 2017 Go to the documentation of location 1.1.2 Download location 1.1.2 archive
1.1.1 Jul 20, 2017 Go to the documentation of location 1.1.1 Download location 1.1.1 archive
1.1.0 Jul 17, 2017 Go to the documentation of location 1.1.0 Download location 1.1.0 archive
1.0.2 Jul 7, 2017 Go to the documentation of location 1.0.2 Download location 1.0.2 archive
1.0.1 Jul 7, 2017 Go to the documentation of location 1.0.1 Download location 1.0.1 archive

All 11 versions...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Jan 21, 2018
  • Dart: 2.0.0-dev.15.0
  • pana: 0.10.0
  • Flutter: 0.0.20

Scores

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

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: flutter.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.40
Transitive dependencies
async 1.13.3 2.0.3
charcode 1.1.1
collection 1.14.3 1.14.5
http 0.11.3+14 0.11.3+16
http_parser 3.1.1
meta 1.1.1 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5