geocode method

Future<GeocodeResponse> geocode({
  1. List<GeocodeAdditionalFeature>? additionalFeatures,
  2. GeocodeAddressNamesMode? addressNamesMode,
  3. List<AddressTranslationComponent>? addressTranslations,
  4. List<double>? biasPosition,
  5. GeocodeFilter? filter,
  6. GeocodeIntendedUse? intendedUse,
  7. String? key,
  8. String? language,
  9. int? maxResults,
  10. String? politicalView,
  11. PostalCodeMode? postalCodeMode,
  12. GeocodeQueryComponents? queryComponents,
  13. String? queryText,
})

Geocode converts a textual address or place into geographic coordinates. You can obtain geographic coordinates, address component, and other related information. It supports flexible queries, including free-form text or structured queries with components like street names, postal codes, and regions. The Geocode API can also provide additional features such as time zone information and the inclusion of political views. Not supported in ap-southeast-1 and ap-southeast-5 regions for GrabMaps customers.

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

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

Parameter additionalFeatures : A list of optional additional parameters, such as time zone, that can be requested for each result.

Parameter addressNamesMode : Specifies how address names are returned. If not set, the service returns normalized (official) names by default. When set to Matched, address names in the response are based on the input query rather than official names. When set to Administrative, the service returns the official administrative names for address components. Administrative currently applies only to addresses in the United States.

Parameter addressTranslations : Specifies which address components to include translations for. Translations include all name variants and alternative names for the requested fields in all available languages. Valid values are District, Locality, Region, and SubRegion.

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). Not supported in ap-southeast-1 and ap-southeast-5 regions for GrabMaps customers.

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: 20

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.

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. If it's populated with the value EnumerateSpannedDistricts, all combinations of the postal code with the corresponding district and city names are returned.

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.

Implementation

Future<GeocodeResponse> geocode({
  List<GeocodeAdditionalFeature>? additionalFeatures,
  GeocodeAddressNamesMode? addressNamesMode,
  List<AddressTranslationComponent>? addressTranslations,
  List<double>? biasPosition,
  GeocodeFilter? filter,
  GeocodeIntendedUse? intendedUse,
  String? key,
  String? language,
  int? maxResults,
  String? politicalView,
  PostalCodeMode? postalCodeMode,
  GeocodeQueryComponents? queryComponents,
  String? queryText,
}) async {
  final $query = <String, List<String>>{
    if (key != null) 'key': [key],
  };
  final $payload = <String, dynamic>{
    if (additionalFeatures != null)
      'AdditionalFeatures': additionalFeatures.map((e) => e.value).toList(),
    if (addressNamesMode != null) 'AddressNamesMode': addressNamesMode.value,
    if (addressTranslations != null)
      'AddressTranslations': addressTranslations.map((e) => e.value).toList(),
    if (biasPosition != null)
      'BiasPosition': biasPosition.map(_s.encodeJsonDouble).toList(),
    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,
    if (queryComponents != null) 'QueryComponents': queryComponents,
    if (queryText != null) 'QueryText': queryText,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/v2/geocode',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return GeocodeResponse(
    resultItems: ($json['ResultItems'] as List?)
        ?.nonNulls
        .map((e) => GeocodeResultItem.fromJson(e as Map<String, dynamic>))
        .toList(),
    pricingBucket: _s.extractHeaderStringValue(
        response.headers, 'x-amz-geo-pricing-bucket')!,
  );
}