searchAutocomplete method

Future<GoogleHTTPResponse<PlacesSuggestions?>> searchAutocomplete({
  1. bool allFields = false,
  2. List<String>? fields,
  3. PlacesSuggestions? instanceFields,
  4. required AutocompleteSearchFilter filter,
})

Searches by text with multiple possible filters. The Autocomplete (New) service is a web service that returns place predictions and query predictions in response to an HTTP request. In the request, specify a text search string and geographic bounds that controls the search area.

The Autocomplete (New) service can match on full words and substrings of the input, resolving place names, addresses, and plus codes. Applications can therefore send queries as the user types, to provide on-the-fly place and query predictions.

Required params:

  • filter: Filters for the search.

Documentation: https://developers.google.com/maps/documentation/places/web-service/place-autocomplete

Implementation

Future<GoogleHTTPResponse<PlacesSuggestions?>> searchAutocomplete({
  /// If true, all fields will be included in the response. It's the same as using fields: ['*'].
  /// Take into account including all fields is expensive in terms of quota usage and performance.
  bool allFields = false,

  /// List of fields to be included in the response by creating a response field mask: https://developers.google.com/maps/documentation/places/web-service/text-search#fieldmask
  /// Take into account this function returns a list of [places], so the fields must be specified with the 'places.' hierarchy in mind, like 'places.id','places.displayName'.
  List<String>? fields,

  /// [Recommended] An instance of PlacesResponse where all fields that are not null will be used as the fields parameter taking into account the field hierarchy, as described here: https://developers.google.com/maps/documentation/places/web-service/text-search#fieldmask
  PlacesSuggestions? instanceFields,

  /// Filters for the search
  required AutocompleteSearchFilter filter,
}) async {
  if (allFields || fields != null || instanceFields != null) {
    fields = _checkFields(
      allFields: allFields,
      fields: fields,
      placeSuggestionsFields: instanceFields,
    );
  }
  return genericParseResponse(
    _service.searchAutocomplete(
      fields: fields,
      filter: filter,
    ),
    dataType: PlacesSuggestions(),
  );
}