38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class MapsController extends GetxController {
|
|
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
|
|
|
final mapsData = <Map<String, dynamic>>[].obs;
|
|
final isLoading = false.obs;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchMapsData();
|
|
}
|
|
|
|
Future<void> fetchMapsData() async {
|
|
isLoading.value = true;
|
|
try {
|
|
final snapshot = await _firestore.collection('history_maps').orderBy('timestamp', descending: true).get();
|
|
|
|
List<Map<String, dynamic>> results = [];
|
|
for (var doc in snapshot.docs) {
|
|
final data = doc.data();
|
|
results.add({
|
|
'timestamp': data['timestamp'] ?? '-',
|
|
'latitude': data['latitude']?.toString() ?? '-',
|
|
'longitude': data['longitude']?.toString() ?? '-',
|
|
});
|
|
}
|
|
mapsData.value = results;
|
|
} catch (e) {
|
|
Get.snackbar("Error", "Failed to load map history: $e");
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
}
|