sendLocation method

Future<void> sendLocation({
  1. required String deviceId,
  2. required double latitude,
  3. required double longitude,
  4. int? timestamp,
})

Envía un punto de rastreo al motor de ingestión.

Lanza una Exception si la API responde con error o hay fallo de red.

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;

  try {
    final response = await _client.post(
      uri,
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': apiKey,
        'User-Agent': 'GeoEngineFlutter/1.0.0',
      },
      body: jsonEncode({
        'device_id': deviceId,
        'latitude': latitude,
        'longitude': longitude,
        'timestamp': ts,
      }),
    );

    if (response.statusCode >= 400) {
      throw Exception('GeoEngine Ingest Error (${response.statusCode}): ${response.body}');
    }
  } catch (e) {
    // Aquí podrías implementar lógica de "Guardar y Reintentar" (Store & Forward)
    // para cuando no hay internet, pero para el SDK base lanzamos el error.
    rethrow;
  }
}