fetchForwardGeo static method

Future<List<ForwardGeo>> fetchForwardGeo({
  1. required String apiKey,
  2. required String query,
})

Implementation

static Future<List<ForwardGeo>> fetchForwardGeo(
    {required String apiKey, required String query}) async {
  const String apiUrl = 'https://us1.locationiq.com/v1/search';
  final String url = '$apiUrl?key=$apiKey&q=$query&format=json';

  final response = await http.get(Uri.parse(url));
  if (response.statusCode == 200) {
    final List<dynamic> data = json.decode(response.body);
    return data.map((e) => ForwardGeo.fromJson(e)).toList();
  } else {
    throw Exception('Impossible de récupérer les places');
  }
}