change mapbox place to google place api
This commit is contained in:
parent
c5de20d64b
commit
48c785c586
@ -180,24 +180,23 @@ class _EditEventState extends State<EditEvent>
|
||||
if (accessToken.isNotEmpty) {
|
||||
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}&types=poi,address,place';
|
||||
var encoded = Uri.encodeFull(url);
|
||||
print("encoded : ${encoded}");
|
||||
final response = await http.get(Uri.parse(encoded));
|
||||
final ApiTokenGoogle = dotenv.env['PLACE_API_KEY'] ?? '';
|
||||
// Searchbox API for geocoding the place (No session token)
|
||||
final searchboxUrl = Uri.parse(
|
||||
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${place}&key=${ApiTokenGoogle}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
// Perform the request
|
||||
final searchboxResponse = await http.get(searchboxUrl);
|
||||
|
||||
if (searchboxResponse.statusCode == 200) {
|
||||
final data = json.decode(searchboxResponse.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
|
||||
if (data['results'].isNotEmpty) {
|
||||
place = data['results'][0]['formatted_address'];
|
||||
final coordinates = data['results'][0]['geometry']['location'];
|
||||
final longitude = coordinates["lng"]; // Longitude
|
||||
final latitude = coordinates["lat"]; // Latitude
|
||||
var urlGet = Uri.parse(
|
||||
"${globals.api}/events/search?item=${name}&date_event=${startDate}&min_lat=$latitude&max_lat=$latitude"
|
||||
"&min_lon=$longitude&max_lon=$longitude");
|
||||
|
@ -170,12 +170,12 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
|
||||
try {
|
||||
await dotenv.load();
|
||||
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
||||
|
||||
final ApiTokenGoogle = dotenv.env['PLACE_API_KEY'] ?? '';
|
||||
// Searchbox API for geocoding the place (No session token)
|
||||
final searchboxUrl = Uri.parse(
|
||||
'https://api.mapbox.com/search/geocode/v6/forward?access_token=${mapboxAccessToken}&q=${place}');
|
||||
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${place}&key=${ApiTokenGoogle}');
|
||||
|
||||
// Perform the request
|
||||
final searchboxResponse = await http.get(searchboxUrl);
|
||||
|
||||
if (searchboxResponse.statusCode != 200) {
|
||||
@ -184,17 +184,17 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
}
|
||||
|
||||
final searchboxData = json.decode(searchboxResponse.body);
|
||||
if (searchboxData['features'].isEmpty) {
|
||||
if (searchboxData['results'].isEmpty) {
|
||||
showErrorDialog(context, "Lieu introuvable");
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract place details from the searchbox response
|
||||
final firstFeature = searchboxData['features'][0];
|
||||
place = firstFeature['properties']["full_address"];
|
||||
final coordinates = firstFeature['geometry']['coordinates'];
|
||||
final longitude = coordinates[0];
|
||||
final latitude = coordinates[1];
|
||||
final firstFeature = searchboxData['results'][0];
|
||||
place = firstFeature["formatted_address"];
|
||||
final coordinates = firstFeature['geometry']['location'];
|
||||
final longitude = coordinates["lng"];
|
||||
final latitude = coordinates["lat"];
|
||||
|
||||
// Check if a similar event exists
|
||||
final eventsUrl = Uri.parse(
|
||||
@ -315,11 +315,9 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
}
|
||||
|
||||
Future<void> searchSuggestions(String input) async {
|
||||
|
||||
String sessionToken = uuid.v4();
|
||||
await dotenv.load(fileName: ".env"); // Load .env file
|
||||
|
||||
final ApiTokenGoogle = dotenv.env['GEMINI_API_KEY'] ?? '';
|
||||
final ApiTokenGoogle = dotenv.env['PLACE_API_KEY'] ?? '';
|
||||
|
||||
// Define the Searchbox API URL
|
||||
final searchboxUrl = Uri.parse(
|
||||
@ -395,7 +393,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
print("suggestion tapped : ${suggestions[index]}");
|
||||
|
||||
setState(() {
|
||||
geographicalZone = suggestions[index]['formatted_address'];
|
||||
geographicalZone =
|
||||
suggestions[index]['formatted_address'];
|
||||
inputGeo.text = geographicalZone;
|
||||
suggestions.clear();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user