placeAutocomplete method
The Place Autocomplete service is a web service that returns place predictions in response to an HTTP request. The request specifies a textual search string and optional geographic bounds. The service can be used to provide autocomplete functionality for text-based geographic searches, by returning places such as businesses, addresses and points of interest as a user types.
Implementation
Future<PlacesAutocompleteResponse> placeAutocomplete({
required String input,
String? language,
List<String>? components,
LatLngLiteral? location,
double? radius,
int? offset,
String? region,
String? sessionToken,
bool? strictBounds,
List<String>? types,
}) async {
final qp = <String, dynamic>{
'input': input,
if (language != null) 'language': language,
if (components != null) 'components': components,
if (location != null) 'location': '${location.lat},${location.lng}',
if (radius != null) 'radius': radius,
if (offset != null) 'offset': offset,
if (region != null) 'region': region,
'sessiontoken': sessionToken ?? generateSessionToken(),
if (strictBounds != null) 'strictBounds': strictBounds,
if (types != null) 'types': types,
};
try {
final data = await doGet(
path: '/maps/api/place/autocomplete/json',
params: qp,
);
return PlacesAutocompleteResponse.fromMap(data);
} catch (error) {
final gr = PlacesAutocompleteResponse.fromError(error.toString());
return gr;
}
}