feat: Add geocoding functionality for trips and enhance activity search with coordinates
This commit is contained in:
@@ -20,6 +20,7 @@ import '../../repositories/group_repository.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import '../../services/place_image_service.dart';
|
||||
import '../../services/trip_geocoding_service.dart';
|
||||
|
||||
/// Create trip content widget for trip creation and editing functionality.
|
||||
///
|
||||
@@ -71,6 +72,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final _userService = UserService();
|
||||
final _groupRepository = GroupRepository();
|
||||
final _placeImageService = PlaceImageService();
|
||||
final _tripGeocodingService = TripGeocodingService();
|
||||
|
||||
/// Trip date variables
|
||||
DateTime? _startDate;
|
||||
@@ -1060,9 +1062,30 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
imageUrl: _selectedImageUrl, // Ajouter l'URL de l'image
|
||||
);
|
||||
|
||||
// Géolocaliser le voyage avant de le sauvegarder
|
||||
Trip tripWithCoordinates;
|
||||
try {
|
||||
print('🌍 [CreateTrip] Géolocalisation en cours pour: ${trip.location}');
|
||||
tripWithCoordinates = await _tripGeocodingService.geocodeTrip(trip);
|
||||
print('✅ [CreateTrip] Géolocalisation réussie: ${tripWithCoordinates.latitude}, ${tripWithCoordinates.longitude}');
|
||||
} catch (e) {
|
||||
print('⚠️ [CreateTrip] Erreur de géolocalisation: $e');
|
||||
// Continuer sans coordonnées en cas d'erreur
|
||||
tripWithCoordinates = trip;
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)'),
|
||||
backgroundColor: Colors.orange,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
// Mode mise à jour
|
||||
tripBloc.add(TripUpdateRequested(trip: trip));
|
||||
tripBloc.add(TripUpdateRequested(trip: tripWithCoordinates));
|
||||
|
||||
await _updateGroupMembers(
|
||||
widget.tripToEdit!.id!,
|
||||
@@ -1072,7 +1095,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
} else {
|
||||
// Mode création - Le groupe sera créé dans le listener TripCreated
|
||||
tripBloc.add(TripCreateRequested(trip: trip));
|
||||
tripBloc.add(TripCreateRequested(trip: tripWithCoordinates));
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
|
||||
Reference in New Issue
Block a user