feat: Add geocoding functionality for trips and enhance activity search with coordinates

This commit is contained in:
Dayron
2025-11-04 20:47:26 +01:00
parent f6c8432335
commit 9cb21c3470
9 changed files with 421 additions and 56 deletions

View File

@@ -19,6 +19,15 @@ class Trip {
/// Trip destination or location.
final String location;
/// Latitude coordinate of the trip location.
final double? latitude;
/// Longitude coordinate of the trip location.
final double? longitude;
/// Timestamp when the location was last geocoded.
final DateTime? lastGeocodingUpdate;
/// Trip start date and time.
final DateTime startDate;
@@ -54,6 +63,9 @@ class Trip {
required this.title,
required this.description,
required this.location,
this.latitude,
this.longitude,
this.lastGeocodingUpdate,
required this.startDate,
required this.endDate,
this.budget,
@@ -101,6 +113,11 @@ class Trip {
title: map['title'] as String? ?? '',
description: map['description'] as String? ?? '',
location: map['location'] as String? ?? '',
latitude: (map['latitude'] as num?)?.toDouble(),
longitude: (map['longitude'] as num?)?.toDouble(),
lastGeocodingUpdate: map['lastGeocodingUpdate'] != null
? _parseDateTime(map['lastGeocodingUpdate'])
: null,
startDate: _parseDateTime(map['startDate']),
endDate: _parseDateTime(map['endDate']),
budget: (map['budget'] as num?)?.toDouble(),
@@ -122,6 +139,11 @@ class Trip {
'title': title,
'description': description,
'location': location,
'latitude': latitude,
'longitude': longitude,
'lastGeocodingUpdate': lastGeocodingUpdate != null
? Timestamp.fromDate(lastGeocodingUpdate!)
: null,
'startDate': Timestamp.fromDate(startDate),
'endDate': Timestamp.fromDate(endDate),
'budget': budget,
@@ -145,6 +167,9 @@ class Trip {
String? title,
String? description,
String? location,
double? latitude,
double? longitude,
DateTime? lastGeocodingUpdate,
DateTime? startDate,
DateTime? endDate,
double? budget,
@@ -160,6 +185,9 @@ class Trip {
title: title ?? this.title,
description: description ?? this.description,
location: location ?? this.location,
latitude: latitude ?? this.latitude,
longitude: longitude ?? this.longitude,
lastGeocodingUpdate: lastGeocodingUpdate ?? this.lastGeocodingUpdate,
startDate: startDate ?? this.startDate,
endDate: endDate ?? this.endDate,
budget: budget ?? this.budget,
@@ -230,9 +258,28 @@ class Trip {
}
}
/// Vérifie si le voyage a des coordonnées géographiques valides
bool get hasCoordinates => latitude != null && longitude != null;
/// Vérifie si les coordonnées sont récentes (moins de 30 jours)
bool get hasRecentCoordinates {
if (!hasCoordinates || lastGeocodingUpdate == null) return false;
final thirtyDaysAgo = DateTime.now().subtract(const Duration(days: 30));
return lastGeocodingUpdate!.isAfter(thirtyDaysAgo);
}
/// Retourne un Map avec les coordonnées pour les services externes
Map<String, dynamic>? get coordinatesMap {
if (!hasCoordinates) return null;
return {
'lat': latitude!,
'lng': longitude!,
};
}
@override
String toString() {
return 'Trip(id: $id, title: $title, location: $location, status: $status)';
return 'Trip(id: $id, title: $title, location: $location, coordinates: ${hasCoordinates ? "($latitude, $longitude)" : "N/A"}, status: $status)';
}
@override