user_location 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

user_location #

pub package travis

A plugin for FlutterMap package to handle and plot the current user location

Usage #

Add flutter_map and user_location to your pubspec.yaml :

  flutter_map: any
  user_location: any # or the latest version on Pub

Update your file with this:


Also make sure that you have added those dependencies in your build.gradle:

  dependencies {
      classpath ''
      classpath ''
  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 #

  • Note: I have not tested the plugin in ios

On iOS you'll need to add the NSLocationWhenInUseUsageDescription to your Info.plist file in order to access the device's location. Simply open your Info.plist file and add the following:

<string>This app needs access to location when open.</string>

If you would like to access the device's location when your App is running in the background, you should also add the NSLocationAlwaysAndWhenInUseUsageDescription (if your App support iOS 10 or earlier you should also add the key NSLocationAlwaysUsageDescription) key to your Info.plist file:

<string>This app needs access to location when in the background.</string>
<string>This app needs access to location when open and in the background.</string>

Installation guide #

  • Declare and initialize MapController mapController = MapController(); List<Marker> markers = [];
  • Add UserLocationPlugin() to plugins
  • Add MarkerLayerOptions and UserLocationOptions in layers

While performing a location update, We remove and add the location marker on the map. Using a single list to hold this location marker along with other markers will unnecessarily also clear them. For that reason, we need to provide an empty marker array to hold the location marker.

Sample code #

import 'package:flutter/material.dart';
import 'package:user_location/user_location.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

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

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'User Location Plugin Demo',
      theme: ThemeData(
      home: HomePage(),

class HomePage extends StatelessWidget {
  MapController mapController = MapController();
  UserLocationOptions userLocationOptions;
  List<Marker> markers = [];
  Widget build(BuildContext context) {
    // You can use the userLocationOptions object to change the properties
    // of UserLocationOptions in runtime
    userLocationOptions = UserLocationOptions(
                context: context,
                mapController: mapController,
                markers: markers,
    return Scaffold(
        appBar: AppBar(title: Text("User Location Plugin")),
        body: FlutterMap(
          options: MapOptions(
            center: LatLng(0,0),
            zoom: 15.0,
            plugins: [
             // ADD THIS
          layers: [
              urlTemplate: ""
              additionalOptions: {
                'accessToken': '<access_token>',
                'id': 'mapbox.streets',
            // ADD THIS
            MarkerLayerOptions(markers: markers),
            // ADD THIS
          // ADD THIS
          mapController: mapController,

Optional parameters #

  • markerWidget overrides the default marker widget
  • markerlocationStream provides the current location of the marker
  • updateMapLocationOnPositionChange moves the map to the current location of the user if set to true
  • showMoveToCurrentLocationFloatingActionButton displays a floating action button at the bottom right of the screen which will redirect the user to their current location. You can also pass your own widget as FAB and control the position using options fabBottom and fabRight options.
  • moveToCurrentLocationFloatingActionButton is a widget when passed overrides the default floating action button. Default floating action button code:
    decoration: BoxDecoration(
    color: Colors.blueAccent,
    borderRadius: BorderRadius.circular(20.0),
    boxShadow: [
        BoxShadow(color: Colors.grey, blurRadius: 10.0)
    child: Icon(
        color: Colors.white,

Run the example #

See the example/ folder for a working example app.

0.1.0 #

  • Upgraded flutter map to v8.0.2
  • Fix map zoom issue #26
  • Upgraded

0.0.9 #

  • adds zoom options to MapController
  • FAB when clicked zooms to current location

0.0.7 #

  • Upgraded the flutter map plugin to 0.80

0.0.5 #

  • Made mapController optional
  • Added FloatingActionButton to redirect map to current location
  • Minor Fixes

0.0.4 #

  • Added Listener for location status of the phone
  • Provides current location of the marker
  • Minor bug fixes

0.0.3 #

  • Added marker to show accuracy
  • Custom user marker widget
  • Removed unnecessary files

0.0.2 #

  • Changed author email id

0.0.1 #

  • TODO: Describe initial release.


user_location_example #

Demonstrates how to use the user_location plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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

  user_location: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:user_location/user_location.dart';
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.

We analyzed this package on Jan 17, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health issues and suggestions

Document public APIs. (-0.38 points)

46 out of 47 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/user_location_options.dart. (-0.50 points)

Analysis of lib/src/user_location_options.dart reported 1 hint:

line 4 col 8: Unused import: 'package:location/location.dart'.

Format lib/src/user_location_layer.dart.

Run flutter format to format lib/src/user_location_layer.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_map ^0.8.2 0.8.2
latlong ^0.6.1 0.6.1
location ^2.3.5 2.3.5
Transitive dependencies
ansicolor 1.0.2
async 2.4.0
cached_network_image 2.0.0
charcode 1.1.2
collection 1.14.11 1.14.12
console_log_handler 1.1.6
convert 2.1.1
crypto 2.1.4
flutter_cache_manager 1.1.3
flutter_image 3.0.0
http 0.12.0+4
http_parser 3.1.3
intl 0.16.1
logging 0.11.4
matcher 0.12.6
meta 1.1.8
path 1.6.4
path_provider 1.5.1
pedantic 1.9.0
platform 2.2.1
positioned_tap_detector 1.0.3
quiver 2.1.2+1
sky_engine 0.0.99
source_span 1.6.0
sqflite 1.2.0
stack_trace 1.9.3
string_scanner 1.0.5
synchronized 2.1.1
term_glyph 1.1.0
transparent_image 1.0.0
tuple 1.0.3
typed_data 1.1.6
uuid 2.0.4
validate 1.7.0
vector_math 2.0.8
Dev dependencies