getAddress method

Future<String?> getAddress(
  1. LocationModel location
)

Implementation

Future<String?> getAddress(LocationModel location) async {
  String host = 'https://maps.google.com/maps/api/geocode/json';
  final url =
      '$host?key=$qKey&language=en&latlng=${location.latitude},${location.longitude}';

  var response = await http.get(Uri.parse(url));
  if (response.statusCode == 200) {
    Map data = jsonDecode(response.body);
    String formattedAddress = data["results"][0]["formatted_address"];

    return formattedAddress;
  } else {
    return null;
  }
}