autocomplete method

Future<AutocompleteResponse> autocomplete({
  1. required String queryText,
  2. List<AutocompleteAdditionalFeature>? additionalFeatures,
  3. List<double>? biasPosition,
  4. AutocompleteFilter? filter,
  5. AutocompleteIntendedUse? intendedUse,
  6. String? key,
  7. String? language,
  8. int? maxResults,
  9. String? politicalView,
  10. PostalCodeMode? postalCodeMode,
})

Autocomplete completes potential places and addresses as the user types, based on the partial input. The API enhances the efficiency and accuracy of address by completing query based on a few entered keystrokes. It helps you by completing partial queries with valid address completion. Also, the API supports the filtering of results based on geographic location, country, or specific place types, and can be tailored using optional parameters like language and political views.

For more information, see Autocomplete in the Amazon Location Service Developer Guide.

May throw AccessDeniedException. May throw InternalServerException. May throw ThrottlingException. May throw ValidationException.

Parameter queryText : The free-form text query to match addresses against. This is usually a partially typed address from an end user in an address box or form.

Parameter additionalFeatures : A list of optional additional parameters that can be requested for each result.

Parameter biasPosition : The position in longitude and latitude that the results should be close to. Typically, place results returned are ranked higher the closer they are to this position. Stored in [lng, lat] and in the WGS 84 format.

Parameter filter : A structure which contains a set of inclusion/exclusion properties that results must possess in order to be returned as a result.

Parameter intendedUse : Indicates if the query results will be persisted in customer infrastructure. Defaults to SingleUse (not stored). Currently, Autocomplete does not support storage of results.

Parameter key : Optional: The API key to be used for authorization. Either an API key or valid SigV4 signature must be provided when making a request.

Parameter language : A list of BCP 47 compliant language codes for the results to be rendered in. If there is no data for the result in the requested language, data will be returned in the default language for the entry.

Parameter maxResults : An optional limit for the number of results returned in a single call.

Default value: 5

Parameter politicalView : The alpha-2 or alpha-3 character code for the political view of a country. The political view applies to the results of the request to represent unresolved territorial claims through the point of view of the specified country.

The following political views are currently supported:

  • ARG: Argentina's view on the Southern Patagonian Ice Field and Tierra Del Fuego, including the Falkland Islands, South Georgia, and South Sandwich Islands
  • EGY: Egypt's view on Bir Tawil
  • IND: India's view on Gilgit-Baltistan
  • KEN: Kenya's view on the Ilemi Triangle
  • MAR: Morocco's view on Western Sahara
  • RUS: Russia's view on Crimea
  • SDN: Sudan's view on the Halaib Triangle
  • SRB: Serbia's view on Kosovo, Vukovar, and Sarengrad Islands
  • SUR: Suriname's view on the Courantyne Headwaters and Lawa Headwaters
  • SYR: Syria's view on the Golan Heights
  • TUR: Turkey's view on Cyprus and Northern Cyprus
  • TZA: Tanzania's view on Lake Malawi
  • URY: Uruguay's view on Rincon de Artigas
  • VNM: Vietnam's view on the Paracel Islands and Spratly Islands

Parameter postalCodeMode : The PostalCodeMode affects how postal code results are returned. If a postal code spans multiple localities and this value is empty, partial district or locality information may be returned under a single postal code result entry. If it's populated with the value EnumerateSpannedLocalities, all cities in that postal code are returned.

Implementation

Future<AutocompleteResponse> autocomplete({
  required String queryText,
  List<AutocompleteAdditionalFeature>? additionalFeatures,
  List<double>? biasPosition,
  AutocompleteFilter? filter,
  AutocompleteIntendedUse? intendedUse,
  String? key,
  String? language,
  int? maxResults,
  String? politicalView,
  PostalCodeMode? postalCodeMode,
}) async {
  final $query = <String, List<String>>{
    if (key != null) 'key': [key],
  };
  final $payload = <String, dynamic>{
    'QueryText': queryText,
    if (additionalFeatures != null)
      'AdditionalFeatures': additionalFeatures.map((e) => e.value).toList(),
    if (biasPosition != null) 'BiasPosition': biasPosition,
    if (filter != null) 'Filter': filter,
    if (intendedUse != null) 'IntendedUse': intendedUse.value,
    if (language != null) 'Language': language,
    if (maxResults != null) 'MaxResults': maxResults,
    if (politicalView != null) 'PoliticalView': politicalView,
    if (postalCodeMode != null) 'PostalCodeMode': postalCodeMode.value,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/v2/autocomplete',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return AutocompleteResponse(
    resultItems: ($json['ResultItems'] as List?)
        ?.nonNulls
        .map(
            (e) => AutocompleteResultItem.fromJson(e as Map<String, dynamic>))
        .toList(),
    pricingBucket: _s.extractHeaderStringValue(
        response.headers, 'x-amz-geo-pricing-bucket')!,
  );
}