getAddress method

dynamic getAddress(
  1. LatLng? location
)

Implementation

getAddress(LatLng? location) async {
  try {
    final endpoint =
        'https://maps.googleapis.com/maps/api/geocode/json?latlng=${location?.latitude},${location?.longitude}'
        '&key=${widget.apiKey}&language=${widget.language}';

    final response = jsonDecode((await http.get(
      Uri.parse(endpoint),
    ))
        .body);
    setState(() {
      _currentAddress = response['results'][0]['formatted_address'];
      _shortName =
      response['results'][0]['address_components'][1]['long_name'];
    });
  } catch (e) {
    print(e);
  }

  setState(() {
    loading = false;
  });
}