geolocation 0.1.0

  • Example
  • Installing
  • Versions
  • 45

Geolocation #

Flutter geolocation plugin that works on Android API 16+ and iOS 9+.


  • Automatic permission management
  • Retrieve last known location
  • Request single location update

Plugin is under active development and will feature soon:

  • Continuous location updates with foreground and background strategies
  • Geocode
  • Geofences
  • Place suggestions
  • Activity recognition

Documentation will improve as well.

Demo app #


Getting Started #

Add geolocation to your pubspec.yaml:

  geolocation: ^0.1.0


The iOS code of geolocation plugin is written in swift. There is a known issue for integrating swift written plugin into Flutter project created with Objective-C template. See #16049 for help on integration.

Permission #

In order to work with location, app needs to specify location permission in configuration file and request it at runtime. Geolocation plugin will check at runtime if permission configuration is missing, and throw an exception otherwise.

iOS configuration #

Depending on the iOS version you target, you need to add to Infos.plist:

  • iOS 9/10: NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription
  • iOS 11+: NSLocationAlwaysAndWhenInUseUsageDescription or NSLocationWhenInUseUsageDescription

Depending if you specify permission description for when in use or always in Infos.plist, geolocation plugin will automatically request the proper associated permission at runtime.

Android configuration #

You need to add one of the following permission to AndroidManifest.xml:

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


Runtime request #

On iOS and on Android API 23+, app also needs to request permission at runtime. Geolocation plugin handles it automatically. If the user denied location permission, location result will contain the following error:

LocationResult result = ...
result.isSuccessful // => false
result.error.type // => GeolocationResultErrorType.permissionDenied

Location result #

All geolocation API related to getting a location returns a Future<LocationResult>.

final LocationResult result = await Geolocation.XXX;

if (result.isSuccessful) {
  // location request successful, location is guaranteed to not be null 
  double lat = result.location.latitude;
  double lng = result.location.longitude;
} else {
  switch (result.error.type) {
    case GeolocationResultErrorType.runtime:
      // runtime error, check result.error.message
    case GeolocationResultErrorType.locationNotFound:
      // location request did not return any result
    case GeolocationResultErrorType.serviceDisabled:
      // location services disabled on device
      // might be that GPS is turned off, or parental control (android) 
    case GeolocationResultErrorType.permissionDenied:
      // user denied location permission request
      // rejection is final on iOS, and can be on Android
      // user will need to manually allow the app from the settings
    case GeolocationResultErrorType.playServicesUnavailable:
      // android only
      // result.error.additionalInfo contains more details on the play services error
      switch(result.error.additionalInfo as GeolocationAndroidPlayServices) {
        case GeolocationAndroidPlayServices.missing:
        case GeolocationAndroidPlayServices.updating:
        case GeolocationAndroidPlayServices.versionUpdateRequired:
        case GeolocationAndroidPlayServices.disabled:
        case GeolocationAndroidPlayServices.invalid:

Single location #

Last known location #

See api documentation: [link]

LocationResult result = await Geolocation.lastKnownLocation;

Current location #

See api documentation: [link]

LocationResult result = await Geolocation.currentLocation(;

Single location update #

See api documentation: [link]

LocationResult result = await Geolocation.singleLocationUpdate(;

[0.1.0] - Initial release

  • New feature: Last known location
  • New feature: Current location
  • New feature: Location updates


//  Copyright (c) 2018 Loup Inc.
//  Licensed under Apache License v2.0

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'tab_location.dart';

void main() => runApp(new MyApp());

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

class _MyAppState extends State<MyApp> {

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new CupertinoTabScaffold(
        tabBar: new CupertinoTabBar(
          items: <BottomNavigationBarItem>[
            new BottomNavigationBarItem(
              title: new Text('Current'),
              icon: new Icon(Icons.location_on),
            new BottomNavigationBarItem(
              title: new Text('Track'),
              icon: new Icon(Icons.location_searching),
            new BottomNavigationBarItem(
              title: new Text('Geocode'),
              icon: new Icon(Icons.location_city),
        tabBuilder: (BuildContext context, int index) {
          return new CupertinoTabView(
            builder: (BuildContext context) {
              switch (index) {
                case 0:
                  return new TabLocation();
                  return new Container(
                    child: new Center(
                      child: new Text('TBD'),

Use this package as a library

1. Depend on it

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

  geolocation: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or 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:geolocation/geolocation.dart';
Version Uploaded Documentation Archive
0.2.1 Apr 12, 2018 Go to the documentation of geolocation 0.2.1 Download geolocation 0.2.1 archive
0.2.0 Apr 12, 2018 Go to the documentation of geolocation 0.2.0 Download geolocation 0.2.0 archive
0.1.1 Apr 3, 2018 Go to the documentation of geolocation 0.1.1 Download geolocation 0.1.1 archive
0.1.0 Apr 3, 2018 Go to the documentation of geolocation 0.1.0 Download geolocation 0.1.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK <2.0.0