change place api mapbox to google place api

This commit is contained in:
Valentin CZERYBA 2024-12-25 22:18:02 +01:00
parent 43124d9cb9
commit c5de20d64b

View File

@ -315,15 +315,15 @@ class _UpdateeventImageState extends State<UpdateeventImage>
}
Future<void> searchSuggestions(String input) async {
var uuid = Uuid();
String sessionToken = uuid.v4();
await dotenv.load(fileName: ".env"); // Load .env file
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
final ApiTokenGoogle = dotenv.env['GEMINI_API_KEY'] ?? '';
// Define the Searchbox API URL
final searchboxUrl = Uri.parse(
'https://api.mapbox.com/search/searchbox/v1/suggest?q=${input}&limit=5&language=en&types=place,poi,address&session_token=${sessionToken}&access_token=${mapboxAccessToken}');
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${input}&key=${ApiTokenGoogle}');
// Perform the request
final response = await http.get(searchboxUrl);
@ -335,11 +335,11 @@ class _UpdateeventImageState extends State<UpdateeventImage>
setState(() {
// Map the results to extract name and full_address
suggestions = (data['suggestions'] as List)
suggestions = (data['results'] as List)
.map((feature) => {
'name': feature['name'],
'full_address': feature[
'full_address'] // Adjusted to match the data structure
'formatted_address': feature[
'formatted_address'] // Adjusted to match the data structure
})
.toList();
});
@ -390,12 +390,12 @@ class _UpdateeventImageState extends State<UpdateeventImage>
itemBuilder: (context, index) {
return ListTile(
title: Text(suggestions[index]['name']),
subtitle: Text(suggestions[index]['full_address']),
subtitle: Text(suggestions[index]['formatted_address']),
onTap: () async {
print("suggestion tapped : ${suggestions[index]}");
setState(() {
geographicalZone = suggestions[index]['full_address'];
geographicalZone = suggestions[index]['formatted_address'];
inputGeo.text = geographicalZone;
suggestions.clear();
});