All Projects → Lyokone → Flutterlocation

Lyokone / Flutterlocation

Licence: mit
A Flutter plugin to easily handle realtime location in iOS and Android. Provides settings for optimizing performance or battery.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutterlocation

Plugins
Flutter plugins created by Rody Davis
Stars: ✭ 424 (-40.37%)
Mutual labels:  flutter-plugin
Flutter Ffmpeg
FFmpeg plugin for Flutter
Stars: ✭ 494 (-30.52%)
Mutual labels:  flutter-plugin
Flutter secure storage
A Flutter plugin to store data in secure storage
Stars: ✭ 587 (-17.44%)
Mutual labels:  flutter-plugin
Flutter easyloading
✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web
Stars: ✭ 455 (-36.01%)
Mutual labels:  flutter-plugin
Amap map fluttify
高德地图 地图组件 Flutter插件
Stars: ✭ 479 (-32.63%)
Mutual labels:  flutter-plugin
Flutter showcaseview
Flutter plugin that allows you to showcase your features on iOS and Android. 👌🔝🎉
Stars: ✭ 502 (-29.4%)
Mutual labels:  flutter-plugin
Flutter facebook login
A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.
Stars: ✭ 387 (-45.57%)
Mutual labels:  flutter-plugin
Flutter Examples
An ultimate cheatbook of curated designs
Stars: ✭ 675 (-5.06%)
Mutual labels:  flutter-plugin
Responsiveframework
Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple. Demo: https://gallery.codelessly.com/flutterwebsites/minimal/
Stars: ✭ 476 (-33.05%)
Mutual labels:  flutter-plugin
Flutter downloader
Flutter Downloader - A plugin for creating and managing download tasks. Supports iOS and Android. Maintainer: @hnvn
Stars: ✭ 546 (-23.21%)
Mutual labels:  flutter-plugin
Audioplayer
A flutter plugin to play audio files iOS / Android / MacOS / Web ( Swift/Java )
Stars: ✭ 461 (-35.16%)
Mutual labels:  flutter-plugin
Flutter Development Roadmap
Flutter App Developer Roadmap - A complete roadmap to learn Flutter App Development. I tried to learn flutter using this roadmap. If you want to add something please contribute to the project. Happy Learning
Stars: ✭ 474 (-33.33%)
Mutual labels:  flutter-plugin
Catcher
Flutter error catching & handling plugin. Handles and reports exceptions in your app!
Stars: ✭ 505 (-28.97%)
Mutual labels:  flutter-plugin
Flutter bugly
腾讯Bugly flutter应用更新统计及异常上报插件,支持Android、iOS
Stars: ✭ 446 (-37.27%)
Mutual labels:  flutter-plugin
Flutter candies
custom flutter candies(widgets) for you to build flutter app easily, enjoy it
Stars: ✭ 638 (-10.27%)
Mutual labels:  flutter-plugin
Flutter effects
flutter animation effects | custom widget | custom renderobject
Stars: ✭ 421 (-40.79%)
Mutual labels:  flutter-plugin
Dart pdf
Pdf creation module for dart/flutter
Stars: ✭ 500 (-29.68%)
Mutual labels:  flutter-plugin
Liquid swipe flutter
A flutter based liquid swipe
Stars: ✭ 680 (-4.36%)
Mutual labels:  flutter-plugin
Bottom navy bar
A beautiful and animated bottom navigation
Stars: ✭ 653 (-8.16%)
Mutual labels:  flutter-plugin
Flutter Learning
🔥 👍 🌟 ⭐ ⭐⭐ Flutter all you want.Flutter install,flutter samples,Flutter projects,Flutter plugin,Flutter problems,Dart codes,etc.Flutter安装和配置,Flutter开发遇到的难题,Flutter示例代码和模板,Flutter项目实战,Dart语言学习示例代码。
Stars: ✭ 4,941 (+594.94%)
Mutual labels:  flutter-plugin

Flutter Location Plugin

pub package Cirrus CI - Task and Script Build Status codecov

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

Youtube Video

Getting Started

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

dependencies:
  location: ^4.0.0

Android

With Flutter 1.12, all the dependencies are automatically added to your project. If your project was created before Flutter 1.12, you may need to follow this.

To use location background mode on Android you have to use the enableBackgroundMode({bool enable}) API before trying to access location in the background and add nescessary permissions. You should place the required permissions in your applications <your-app>/android/app/src/main/AndroidManifest.xml:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

Remember that the user has to accept the location permission to always allow to use background location. From Android 11 option to always allow is not presented on the location permission dialog prompt. The user has to enable it manually from the app settings and this should be explained to the user on a separate UI that redirects user to app's location settings managed by the operating system. More on that topic can be found on Android developer pages.

iOS

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

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

To receive location when application is in background, to Info.plist you have to add property list key :

UIBackgroundModes

with string value:

location

Web

Nothing to do, the plugin works directly out of box.

macOS

Ensure that the application is properly "sandboxed" and that the location is enabled. You can do this in Xcode with the following steps:

  1. In the project navigator, click on your application's target. This should bring up a view with tabs such as "General", "Capabilities", "Resource Tags", etc.
  2. Click on the "Capabilities" tab. This will give you a list of items such as "App Groups", "App Sandbox" and so on. Each item will have an "On/Off" button.
  3. Turn on the "App Sandbox" item and press the ">" button on the left to show the sandbox stuff.
  4. In the "App Data" section, select "Location".

Add this permission in Info.plist :

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

Usage

Then you just have to import the package with

import 'package:location/location.dart';

In order to request location, you should always check manually Location Service status and Permission status.

Location location = new Location();

bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;

_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
  _serviceEnabled = await location.requestService();
  if (!_serviceEnabled) {
    return;
  }
}

_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
  _permissionGranted = await location.requestPermission();
  if (_permissionGranted != PermissionStatus.granted) {
    return;
  }
}

_locationData = await location.getLocation();

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

location.onLocationChanged.listen((LocationData currentLocation) {
  // Use current location
});

To receive location when application is in background you have to enable it:

location.enableBackgroundMode(enable: true)

Be sure to check the example project to get other code samples.

On Android a foreground notification is displayed with information that location service is running in the background.

On iOS while app is in the background and gets location, blue system bar notifies User about updates. Tapping on this bar moves User back to the app.

Androig background location iOS background location

Public Methods Summary

Return Description
Future<PermissionStatus> requestPermission()
Request the Location permission. Return a PermissionStatus to know if the permission has been granted.
Future<PermissionStatus> hasPermission()
Return a PermissionStatus to know the state of the location permission.
Future<bool> serviceEnabled()
Return a boolean to know if the Location Service is enabled or if the user manually deactivated it.
Future<bool> requestService()
Show an alert dialog to request the user to activate the Location Service. On iOS, will only display an alert due to Apple Guidelines, the user having to manually go to Settings. Return a boolean to know if the Location Service has been activated (always false on iOS).
Future<bool> changeSettings(LocationAccuracy accuracy = LocationAccuracy.HIGH, int interval = 1000, double distanceFilter = 0)
Will change the settings of futur requests. accuracywill describe the accuracy of the request (see the LocationAccuracy object). interval will set the desired interval for active location updates, in milliseconds (only affects Android). distanceFilter set the minimum displacement between location updates in meters.
Future<LocationData> getLocation()
Allow to get a one time position of the user. It will try to request permission if not granted yet and will throw a PERMISSION_DENIED error code if permission still not granted.
Stream<LocationData> onLocationChanged
Get the stream of the user's location. It will try to request permission if not granted yet and will throw a PERMISSION_DENIED error code if permission still not granted.
Future<bool> enableBackgroundMode({bool enable})
Allow or disallow to retrieve location events in the background. Return a boolean to know if background mode was successfully enabled.

You should try to manage permission manually with requestPermission() to avoid error, but plugin will try handle some cases for you.

Objects

class LocationData {
  final double latitude; // Latitude, in degrees
  final double longitude; // Longitude, in degrees
  final double accuracy; // Estimated horizontal accuracy of this location, radial, in meters
  final double altitude; // In meters above the WGS 84 reference ellipsoid
  final double speed; // In meters/second
  final double speedAccuracy; // In meters/second, always 0 on iOS
  final double heading; //Heading is the horizontal direction of travel of this device, in degrees
  final double time; //timestamp of the LocationData
}


enum LocationAccuracy {
  powerSave, // To request best accuracy possible with zero additional power consumption,
  low, // To request "city" level accuracy
  balanced, // To request "block" level accuracy
  high, // To request the most accurate locations available
  navigation // To request location for navigation usage (affect only iOS)
}

// Status of a permission request to use location services.
enum PermissionStatus {
  /// The permission to use location services has been granted.
  granted,
  // The permission to use location services has been denied by the user. May have been denied forever on iOS.
  denied,
  // The permission to use location services has been denied forever by the user. No dialog will be displayed on permission request.
  deniedForever
}

Note: you can convert the timestamp into a DateTime with: DateTime.fromMillisecondsSinceEpoch(locationData.time.toInt())

Feedback

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].