From 79f457eec196d6439d47808bc64ca0d0551e27d4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 16 Nov 2024 20:06:58 +0100 Subject: [PATCH] more precise search --- covas_mobile/lib/pages/UpdateEventImage.dart | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index cd32624..44cbd09 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -159,14 +159,19 @@ class _UpdateeventImageState extends State try { await dotenv.load(); final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; + print("place non encoded : ${place}"); final url = - 'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&proximity=ip'; - final response = await http.get(Uri.parse(url)); + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&types=poi,address,place'; + var encoded = Uri.encodeFull(url); + print("encoded : ${encoded}"); + final response = await http.get(Uri.parse(encoded)); if (response.statusCode == 200) { final data = json.decode(response.body); + print("data : ${data}"); if (data['features'].isNotEmpty) { + place = data['features'][0]['place_name']; final coordinates = data['features'][0]['geometry']['coordinates']; final longitude = coordinates[0]; // Longitude final latitude = coordinates[1]; // Latitude @@ -316,15 +321,19 @@ class _UpdateeventImageState extends State final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; final url = - 'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&proximity=ip'; - final response = await http.get(Uri.parse(url)); + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&types=poi,address,place'; + var encoded = Uri.encodeFull(url); + final response = await http.get(Uri.parse(encoded)); + print("response code suggesttion : ${response.statusCode}"); if (response.statusCode == 200) { final data = json.decode(response.body); + print("data suggestion : ${data}"); setState(() { suggestions = (data['features'] as List) .map((feature) => { 'place_name': feature['place_name'], + 'text': feature['text'], 'geometry': feature[ 'geometry'], // Include geometry for latitude/longitude }) @@ -378,13 +387,14 @@ class _UpdateeventImageState extends State return ListTile( title: Text(suggestions[index]['place_name']), onTap: () async { + print("suggestion tapped : ${suggestions[index]}"); final latitude = suggestions[index]['geometry']['coordinates'][1]; final longitude = suggestions[index]['geometry']['coordinates'][0]; setState(() { - geographicalZone = suggestions[index]['place_name']; + geographicalZone = suggestions[index]['text']; inputGeo.text = geographicalZone; suggestions.clear(); });