From 43124d9cb9d9677fc174704f97b2591d5e1f6661 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 22 Dec 2024 22:37:17 +0100 Subject: [PATCH] add list adress from v6 mapbox and searchbox --- covas_mobile/lib/pages/UpdateEventImage.dart | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index 1f544ca..5532b92 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -173,14 +173,8 @@ class _UpdateeventImageState extends State final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; // Searchbox API for geocoding the place (No session token) - final searchboxUrl = - Uri.parse('https://api.mapbox.com/search/searchbox/v1/retrieve/') - .replace(queryParameters: { - 'access_token': mapboxAccessToken, - 'query': place, - 'limit': '1', - 'types': 'place,address', - }); + final searchboxUrl = Uri.parse( + 'https://api.mapbox.com/search/geocode/v6/forward?access_token=${mapboxAccessToken}&q=${place}'); final searchboxResponse = await http.get(searchboxUrl); @@ -197,7 +191,7 @@ class _UpdateeventImageState extends State // Extract place details from the searchbox response final firstFeature = searchboxData['features'][0]; - place = firstFeature['place_name']; + place = firstFeature['properties']["full_address"]; final coordinates = firstFeature['geometry']['coordinates']; final longitude = coordinates[0]; final latitude = coordinates[1]; @@ -345,8 +339,7 @@ class _UpdateeventImageState extends State .map((feature) => { 'name': feature['name'], 'full_address': feature[ - 'place_formatted'], // Adjusted to match the data structure - 'context': feature['context'], // Additional context data + 'full_address'] // Adjusted to match the data structure }) .toList(); }); @@ -402,7 +395,7 @@ class _UpdateeventImageState extends State print("suggestion tapped : ${suggestions[index]}"); setState(() { - geographicalZone = suggestions[index]['name']; + geographicalZone = suggestions[index]['full_address']; inputGeo.text = geographicalZone; suggestions.clear(); });