sendLocation method
Implementation
Future<void> sendLocation({
required String deviceId,
required double latitude,
required double longitude,
int? timestamp,
}) async {
final uri = Uri.parse('$ingestUrl/ingest');
final ts = timestamp ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
final body = jsonEncode({
'device_id': deviceId,
'latitude': latitude,
'longitude': longitude,
'timestamp': ts,
});
if (debug) print('📡 [GeoEngine] Sending location for $deviceId...');
try {
final response = await _client.post(
uri,
headers: _headers,
body: body,
).timeout(timeout);
if (response.statusCode >= 400) {
throw GeoEngineException(
'Ingest Failed: ${response.body}',
statusCode: response.statusCode
);
}
if (debug) print('[GeoEngine] Location sent successfully.');
} on TimeoutException {
throw GeoEngineException('Connection timed out after ${timeout.inSeconds}s');
} catch (e) {
if (debug) print('[GeoEngine] Error: $e');
rethrow;
}
}