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