A Flutter plugin to fetch GPS/ Network based Location Data Feed on Android, made with <3
MIT License
A Flutter plugin to fetch GPS/ Network based Location Data Feed on Android.
locate v1.2.0 is readily availble for use.
locate
can be used on Android for fetching Location Data Feed.
Two location service providers are available
It has androidX support, along with latest version of all dependencies.
locate
as dependency in in your flutter project's pubspec.yamldependencies:
locate: ^1.2.0
$ flutter pub get
locate
in your dart code & start getting location data feedimport 'package:locate/locate.dart';
First thing first, add permission declaration in your project's AndroidManifest.xml
.
<uses-permission android:name="android.permission.ACCESS_{FINE, COARSE}_LOCATION"/>
var _locate = Locate();
_locate.requestLocationPermission().then((bool result) {
if (result)
// we're good to go
else
// let user know it's required
});
_locate.enableLocation().then((bool result) {
if (result) {
// update UI & request *locate* for location Data
setState(() => _areWeGettingLocationUpdate = true);
// Location data will be fetched and delivered as Stream<MyLocation>
else
// user didn't enable location
}
});
_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,
onError: (e) => print(e),
);
_locate.stopLocationDataFeed().then((bool result) {
// do some UI updation kind of work/ or something else
});
/// 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);
// 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();
Here's an example application using all these API(s).
You can also set some optional named parameters while invoking methods from Locate class.
While requesting permission, you can set provider
Before requesting Location Data Feed, you can also set via which location manager to fetch data and location data provider name.
LocationServiceProvider.GMSBasedLocation
, make sure you've declared & requested for permission of accessing FINE Location.LocationServiceProvider.LocationManagerBasedLocation
as locationServiceProvider
, you may use any of them, depending upon your declared & requested permissions.
LocationProvider.GPS
LocationProvider.Network