fix lat lng
This commit is contained in:
@@ -126,7 +126,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
setState(() {
|
setState(() {
|
||||||
userPosition = mapbox.Point(
|
userPosition = mapbox.Point(
|
||||||
coordinates:
|
coordinates:
|
||||||
mapbox.Position(position.latitude, position.longitude));
|
mapbox.Position(position.longitude, position.latitude));
|
||||||
isUserPositionInitialized = true;
|
isUserPositionInitialized = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,18 +139,32 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
|
|||||||
Future<void> _fetchRoute(
|
Future<void> _fetchRoute(
|
||||||
mapbox.Point origin, mapbox.Point destination, String mode) async {
|
mapbox.Point origin, mapbox.Point destination, String mode) async {
|
||||||
final url = Uri.parse(
|
final url = Uri.parse(
|
||||||
'https://api.mapbox.com/directions/v5/mapbox/$mode/${origin.coordinates.lng},${origin.coordinates.lat};${destination.coordinates.lng},${destination.coordinates.lat}?geometries=geojson&access_token=${dotenv.env['MAPBOX_ACCESS_TOKEN']}',
|
'https://api.mapbox.com/directions/v5/mapbox/$mode/'
|
||||||
|
'${origin.coordinates.lng},${origin.coordinates.lat};'
|
||||||
|
'${destination.coordinates.lng},${destination.coordinates.lat}'
|
||||||
|
'?geometries=geojson&access_token=${dotenv.env['MAPBOX_ACCESS_TOKEN']}',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(response.body);
|
||||||
final geometry = data['routes'][0]['geometry']['coordinates'];
|
|
||||||
setState(() {
|
// Vérifie si 'routes' existe et contient au moins 1 élément
|
||||||
routeCoordinates = (geometry as List)
|
if (data['routes'] != null && (data['routes'] as List).isNotEmpty) {
|
||||||
.map<List<double>>((coord) => [coord[0], coord[1]])
|
final geometry = data['routes'][0]['geometry']['coordinates'];
|
||||||
.toList();
|
|
||||||
});
|
setState(() {
|
||||||
|
routeCoordinates = (geometry as List)
|
||||||
|
.map<List<double>>((coord) => [coord[0], coord[1]])
|
||||||
|
.toList();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
debugPrint("⚠️ Aucune route trouvée entre ${origin} et $destination.");
|
||||||
|
// Optionnel : afficher un snackbar/toast à l’utilisateur
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debugPrint("❌ Erreur API Mapbox: ${response.statusCode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user