more precise search
This commit is contained in:
parent
74e55f3d6b
commit
79f457eec1
@ -159,14 +159,19 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
try {
|
try {
|
||||||
await dotenv.load();
|
await dotenv.load();
|
||||||
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
||||||
|
print("place non encoded : ${place}");
|
||||||
final url =
|
final url =
|
||||||
'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&proximity=ip';
|
'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&types=poi,address,place';
|
||||||
final response = await http.get(Uri.parse(url));
|
var encoded = Uri.encodeFull(url);
|
||||||
|
print("encoded : ${encoded}");
|
||||||
|
final response = await http.get(Uri.parse(encoded));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
print("data : ${data}");
|
||||||
|
|
||||||
if (data['features'].isNotEmpty) {
|
if (data['features'].isNotEmpty) {
|
||||||
|
place = data['features'][0]['place_name'];
|
||||||
final coordinates = data['features'][0]['geometry']['coordinates'];
|
final coordinates = data['features'][0]['geometry']['coordinates'];
|
||||||
final longitude = coordinates[0]; // Longitude
|
final longitude = coordinates[0]; // Longitude
|
||||||
final latitude = coordinates[1]; // Latitude
|
final latitude = coordinates[1]; // Latitude
|
||||||
@ -316,15 +321,19 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
|
|
||||||
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
||||||
final url =
|
final url =
|
||||||
'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&proximity=ip';
|
'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&types=poi,address,place';
|
||||||
final response = await http.get(Uri.parse(url));
|
var encoded = Uri.encodeFull(url);
|
||||||
|
final response = await http.get(Uri.parse(encoded));
|
||||||
|
print("response code suggesttion : ${response.statusCode}");
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
print("data suggestion : ${data}");
|
||||||
setState(() {
|
setState(() {
|
||||||
suggestions = (data['features'] as List)
|
suggestions = (data['features'] as List)
|
||||||
.map((feature) => {
|
.map((feature) => {
|
||||||
'place_name': feature['place_name'],
|
'place_name': feature['place_name'],
|
||||||
|
'text': feature['text'],
|
||||||
'geometry': feature[
|
'geometry': feature[
|
||||||
'geometry'], // Include geometry for latitude/longitude
|
'geometry'], // Include geometry for latitude/longitude
|
||||||
})
|
})
|
||||||
@ -378,13 +387,14 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(suggestions[index]['place_name']),
|
title: Text(suggestions[index]['place_name']),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
print("suggestion tapped : ${suggestions[index]}");
|
||||||
final latitude =
|
final latitude =
|
||||||
suggestions[index]['geometry']['coordinates'][1];
|
suggestions[index]['geometry']['coordinates'][1];
|
||||||
final longitude =
|
final longitude =
|
||||||
suggestions[index]['geometry']['coordinates'][0];
|
suggestions[index]['geometry']['coordinates'][0];
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
geographicalZone = suggestions[index]['place_name'];
|
geographicalZone = suggestions[index]['text'];
|
||||||
inputGeo.text = geographicalZone;
|
inputGeo.text = geographicalZone;
|
||||||
suggestions.clear();
|
suggestions.clear();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user