decodeAndSelectPlace method
To navigate to the selected place from the autocomplete list to the map, the lat,lng is required. This method fetches the lat,lng of the place and proceeds to moving the map to that location.
Implementation
void decodeAndSelectPlace(String placeId) async {
clearOverlay();
final endpoint =
"https://maps.googleapis.com/maps/api/place/details/json?key=${widget.apiKey}"
"&placeid=$placeId"
'&language=${widget.language}';
try {
final response = await http.get(
Uri.parse(endpoint),
);
logger.i(endpoint);
logger.v(response.body);
if (response.statusCode == 200) {
Map<String, dynamic> location =
jsonDecode(response.body)['result']['geometry']['location'];
LatLng latLng = LatLng(location['lat'], location['lng']);
moveToLocation(latLng);
}
} catch (error) {
logger.e(error);
}
}