queryAutocomplete method

Future<PlacesAutocompleteResponse> queryAutocomplete({
  1. required String input,
  2. String? language,
  3. LatLngLiteral? location,
  4. double? radius,
  5. int? offset,
})

The Query Autocomplete service allows you to add on-the-fly geographic query predictions to your application. Instead of searching for a specific location, a user can type in a categorical search, such as "pizza near New York" and the service responds with a list of suggested queries matching the string. As the Query Autocomplete service can match on both full words and substrings, applications can send queries as the user types to provide on-the-fly predictions.

Implementation

Future<PlacesAutocompleteResponse> queryAutocomplete({
  required String input,
  String? language,
  LatLngLiteral? location,
  double? radius,
  int? offset,
}) async {
  final qp = <String, dynamic>{
    'input': input,
    if (language != null) 'language': language,
    if (location != null) 'location': '${location.lat},${location.lng}',
    if (offset != null) 'offset': offset,
    if (radius != null) 'radius': radius,
  };

  try {
    final data = await doGet(
      path: '/maps/api/place/queryautocomplete/json',
      params: qp,
    );

    return PlacesAutocompleteResponse.fromMap(data);
  } catch (error) {
    final gr = PlacesAutocompleteResponse.fromError(error.toString());
    return gr;
  }
}