change place api mapbox to google place api
This commit is contained in:
parent
43124d9cb9
commit
c5de20d64b
@ -315,15 +315,15 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> searchSuggestions(String input) async {
|
Future<void> searchSuggestions(String input) async {
|
||||||
var uuid = Uuid();
|
|
||||||
String sessionToken = uuid.v4();
|
String sessionToken = uuid.v4();
|
||||||
await dotenv.load(fileName: ".env"); // Load .env file
|
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
|
// Define the Searchbox API URL
|
||||||
final searchboxUrl = Uri.parse(
|
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
|
// Perform the request
|
||||||
final response = await http.get(searchboxUrl);
|
final response = await http.get(searchboxUrl);
|
||||||
@ -335,11 +335,11 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
// Map the results to extract name and full_address
|
// Map the results to extract name and full_address
|
||||||
suggestions = (data['suggestions'] as List)
|
suggestions = (data['results'] as List)
|
||||||
.map((feature) => {
|
.map((feature) => {
|
||||||
'name': feature['name'],
|
'name': feature['name'],
|
||||||
'full_address': feature[
|
'formatted_address': feature[
|
||||||
'full_address'] // Adjusted to match the data structure
|
'formatted_address'] // Adjusted to match the data structure
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
});
|
});
|
||||||
@ -390,12 +390,12 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(suggestions[index]['name']),
|
title: Text(suggestions[index]['name']),
|
||||||
subtitle: Text(suggestions[index]['full_address']),
|
subtitle: Text(suggestions[index]['formatted_address']),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
print("suggestion tapped : ${suggestions[index]}");
|
print("suggestion tapped : ${suggestions[index]}");
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
geographicalZone = suggestions[index]['full_address'];
|
geographicalZone = suggestions[index]['formatted_address'];
|
||||||
inputGeo.text = geographicalZone;
|
inputGeo.text = geographicalZone;
|
||||||
suggestions.clear();
|
suggestions.clear();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user