change mapbox place to google place api
This commit is contained in:
@@ -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");
|
||||
|
Reference in New Issue
Block a user