synw / traccar_client

Dart client for the Traccar geolocation server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Traccar client

pub package

Dart client for the Traccar geolocation server. Get real time devices positions updates from a Traccar server.

Usage

Initialize

import 'package:pedantic/pedantic.dart';
import 'package:traccar_client/traccar_client.dart';
import 'conf.dart';

/// [serverUrl] and [userToken] are taken from conf
final trac = Traccar(serverUrl: serverUrl, userToken: userToken);
unawaited(trac.init());
await trac.onReady;

The token is a user token that you can generate from the Traccar web interface

Listen for positions updates

final positions = await trac.positions();
print("Listening for position updates");
positions.listen((device) {
   print("POSITION UPDATE: $device");
   print("${device.id}: ${device.position.geoPoint.latitude} / " +
      "${device.position.geoPoint.longitude}");
});

Get a list of devices

trac.query.devices().then((List<Device> devices) {
   print("$devices");
});

Get positions history for a device

   final List<Device> pos = await trac.query.positions(
      deviceId: "1", since: Duration(hours: 3));

Data structure

Device: representation of a device

GeoPoint: geographical datapoints: data structure

Example

To run the example put your server address and user token in conf.dart

About

Dart client for the Traccar geolocation server

License:MIT License


Languages

Language:Dart 100.0%