fetchReverseGeo static method

Future<ReverseGeo> fetchReverseGeo({
  1. required String apiKey,
  2. required String lat,
  3. required String long,
})

Implementation

static Future<ReverseGeo> fetchReverseGeo(
    {required String apiKey,
    required String lat,
    required String long}) async {
  const String apiUrl = 'https://us1.locationiq.com/v1/reverse';
  final String url = '$apiUrl?key=$apiKey&lat=$lat&lon=$long&format=json';

  final response = await http.get(Uri.parse(url));
  if (response.statusCode == 200) {
    final Map<String, dynamic> data = json.decode(response.body);
    return ReverseGeo.fromJson(data);
  } else {
    throw Exception('Impossible de récupérer les infos');
  }
}