0 purchases
traccar client
Traccar client #
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;
copied to clipboard
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}");
});
copied to clipboard
Run queries #
Query for a list of devices:
trac.query.devices().then((List<Device> devices) {
print("$devices");
});
copied to clipboard
Data structure #
The position stream outputs Device objects with updated positions:
class Device {
final int id;
String uniqueId;
int groupId;
String name;
double batteryLevel;
int keepAlive;
bool isDisabled;
bool isActive;
DevicePosition position;
}
class DevicePosition {
final int id;
final LatLng point;
final double accuracy;
final double altitude;
final double speed;
final double distance;
final double totalDistance;
final String address;
final DateTime date;
}
copied to clipboard
Example #
To run the example put your server address and user token in conf.dart
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.