locate 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

locate #

A Flutter plugin to work with Android Location Services(GPS/ Network).

usage #

This flutter plugin can be used on Android for fetching Location Data using either Google Play Services based Location or LocationManager based Location.

Well this plugin is has androidX support enabled.

Even you can specify whether to use Network provider or GPS provider as Location Data Provider.

Don't forget to add following permission in you AndroidManifest.xml.

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

If you're planning to use Google Play Services based FusedLocationProvider, request for ACCESS_FINE_LOCATION.

Otherwise you may only request for ACCESS_COARSE_LOCATION.

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

how to use API #

Get an intance of Locate class.

var _locate = Locate();

Make sure you first request for Location Permission from user.

_locate.requestLocationPermission().then((bool result) {
                  if (result)
                    // we're good to go
                  else
                    // you may be interested in letting user know about it, that location access permission is required
                  });

Now time to enable Location.

_locate.enableLocation().then((bool result) {
                      if (result) {
                        // setState(() => _areWeGettingLocationUpdate = true);
                        // here you may be interested in updating UI and the request for location Data.
                        // Location data will be fetched and delivered as Stream<MyLocation>
                      else
                        // user didn't enable location
                      }
                    });

And finally, let's request for getting Location Data Feed.

_locate.getLocationDataFeed()
                          ..listen(
                            // we listen for location data, which is received as stream
                            (MyLocation data) =>
                                setState(() => _locationData.add(data)), // as soon as data received,will update UI/ perform some other task using location data.
                            cancelOnError: true, // if some error occurs, Stream will be closed
                            onError: (e) => print(e), // error is displayed
                          );

Aah I just forgot to mention one thing, how to stop listening location update.

_locate.stopLocationDataFeed().then((bool result) {
  // do some UI updation kind of work/ or something else
});

what's MyLocation #

MyLocation class can be thought of as a Location Data Container.

/// constructor of MyLocation
MyLocation(
      this.longitude,
      this.latitude,
      this.time, // in DateTime
      this.altitude, // in meters
      this.bearing, // in degree
      this.speed, // in meters/s
      this.accuracy, // in meters
      this.verticalAccuracy, // in meters
      this.bearingAccuracy, // in meters
      this.speedAccuracy, // in meters/s
      this.provider, // as String,either gps/ network/ fused
      this.satelliteCount);

I've added some companion methods which can be used from MyLocation, such as

// will fetch you name of direction of movement from bearing value
bearingToDirectionName();

// m/s to km/h converion for speedaccuracy
getSpeedAccuracyInKiloMetersPerHour();

/// same as above, but works on speed
getSpeedInKiloMetersPerHour();

/// displays time in pretty format
getParsedTimeString();

important points #

You can also set some optional named parameters while invoking methods from Locate class.

In case of following method, you can also set provider, to be LocationProvider.Network, if you want to use Network based Location only.

requestLocationPermission(
      {String provider: LocationProvider.GPS}); // default value is LocationProvider.GPS

Before requesting Location Data Feed, you can also set via which location manager to fetch data and location data provider name.

Note:: If you are planning use LocationServiceProvider.GMSBasedLocation, for fetching data, make sure you've requested for permission of accessing FINE Location. And also use LocationProvider.GPS as locationProvider parameter's value.

Otherwise while using LocationServiceProvider.LocationManagerBasedLocation as locationServiceProvider, you may either use LocationProvider.GPS or LocationProvider.Network, depending upon your requested permissions.

getLocationDataFeed(
      {String locationServiceProvider:
          LocationServiceProvider.LocationManagerBasedLocation,
      String locationProvider: LocationProvider.GPS});

If you've FINE Location access permission, you can simply request for Network Provider based location data.

Hope it was helpful.

Show some <3, to this venture, by putting star on GitHub.

1.0.0 #

This is the very first release of locate flutter plugin. It simply fetches android location data using either Google Play Service based Location Service or android.location.LocationManager. It can continously report device location using callback mechanism, which might be used to update UI.

This plugin only works for Androd Platform. Built with latest version of SDK(28).

1.1.0 #

Very happy to release a new version of this plugin.

In this release locate, tries to leverage the power of Asynchronous Programming, based on Future

If you've been using it, we'll this might be a bad situttion, but it's a breaking update.

API has been updated, for ease of usability. No callbacks anymore for receiving location data feed, a Stream

Hope it'll be helpful.

example/README.md

locate_example #

Demonstrates how to use the locate plugin.

screen captures #

screen_capture_1

screen_capture_2

screen_capture_3

screen_capture_4

Hope it was helpful :)

Use this package as a library

1. Depend on it

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


dependencies:
  locate: ^1.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:locate/locate.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
96
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/my_location.dart.

Run flutter format to format lib/my_location.dart.

Maintenance suggestions

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test