GeoClue: The Geolocation Service
Geoclue is a D-Bus service that provides location information. It utilizes many sources to best find user's location:
import 'dart:async';
import 'package:geoclue/geoclue.dart';
Future<void> main() async {
final location = await GeoClue.getLocation(desktopId: '<desktop-id>');
print('Current location: $location');
print('Waiting 10s for location updates...');
late final StreamSubscription sub;
sub = GeoClue.getLocationUpdates(desktopId: '<desktop-id>')
.timeout(const Duration(seconds: 10), onTimeout: (_) => sub.cancel())
.listen((location) {
print('... $location');
});
}
We welcome contributions! See the contribution guide for more details.
Run this command:
With Dart:
$ dart pub add geoclue
With Flutter:
$ flutter pub add geoclue
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get
):
dependencies:
geoclue: ^0.1.1
Alternatively, your editor might support dart pub get
or flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:geoclue/geoclue.dart';
GeoClue for Dart examples
Simple Where Am I? examples using GeoClue to get the current location and listen to location updates.
A minimal example that uses the simplified GeoClue
convenience API.
A more advanced example that uses the GeoClueManager
and GeoClueClient
classes.
Author: canonical
Source: https://github.com/canonical/geoclue.dart
License: MPL-2.0 license