Skip to content

geocode async

geocode(
    *,
    config_overrides: Optional[AsyncGeoPlacesClientConfig] = None,
    query_text: Optional[SensitiveString] = None,
    query_components: Optional[GeocodeQueryComponents] = None,
    max_results: Optional[int] = None,
    bias_position: Optional[Position] = None,
    filter: Optional[GeocodeFilter] = None,
    additional_features: Optional[GeocodeAdditionalFeatureList] = None,
    language: Optional[LanguageTag] = None,
    political_view: Optional[CountryCode] = None,
    intended_use: Optional[GeocodeIntendedUse] = None,
    key: Optional[ApiKey] = None,
    postal_code_mode: Optional[PostalCodeMode] = None,
    address_translations: Optional[AddressTranslationComponentList] = None,
    address_names_mode: Optional[GeocodeAddressNamesMode] = None,
) -> GeocodeResponse

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.

Parameters:

  • query_text (Optional[SensitiveString], default: None ) –

    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.

  • max_results (Optional[int], default: None ) –

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

    Default value: 20

  • bias_position (Optional[Position], default: None ) –

    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.

  • filter (Optional[GeocodeFilter], default: None ) –

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

  • additional_features (Optional[GeocodeAdditionalFeatureList], default: None ) –

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

  • language (Optional[LanguageTag], default: None ) –

    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.

  • political_view (Optional[CountryCode], default: None ) –

    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.

  • intended_use (Optional[GeocodeIntendedUse], default: None ) –

    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.

    When storing Geocode responses, you must set this field to Storage to comply with the terms of service. These requests will be charged at a higher rate. Please review the user agreement and service pricing structure to determine the correct setting for your use case.

  • key (Optional[ApiKey], default: None ) –

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

  • postal_code_mode (Optional[PostalCodeMode], default: None ) –

    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.

  • address_translations (Optional[AddressTranslationComponentList], default: None ) –

    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.

  • address_names_mode (Optional[GeocodeAddressNamesMode], default: None ) –

    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.

Raises:

Source code in docs_src/capo_geo_places/_services/async_geo_places.py
async def geocode(
    self,
    *,
    config_overrides: Optional[AsyncGeoPlacesClientConfig] = None,
    query_text: Optional[
        "capo_geo_places.types.sensitive_string.SensitiveString"
    ] = None,
    query_components: Optional[
        "capo_geo_places.types.geocode_query_components.GeocodeQueryComponents"
    ] = None,
    max_results: Optional[int] = None,
    bias_position: Optional["capo_geo_places.types.position.Position"] = None,
    filter: Optional["capo_geo_places.types.geocode_filter.GeocodeFilter"] = None,
    additional_features: Optional[
        "capo_geo_places.types.geocode_additional_feature_list.GeocodeAdditionalFeatureList"
    ] = None,
    language: Optional["capo_geo_places.types.language_tag.LanguageTag"] = None,
    political_view: Optional[
        "capo_geo_places.types.country_code.CountryCode"
    ] = None,
    intended_use: Optional[
        "capo_geo_places.types.geocode_intended_use.GeocodeIntendedUse"
    ] = None,
    key: Optional["capo_geo_places.types.api_key.ApiKey"] = None,
    postal_code_mode: Optional[
        "capo_geo_places.types.postal_code_mode.PostalCodeMode"
    ] = None,
    address_translations: Optional[
        "capo_geo_places.types.address_translation_component_list.AddressTranslationComponentList"
    ] = None,
    address_names_mode: Optional[
        "capo_geo_places.types.geocode_address_names_mode.GeocodeAddressNamesMode"
    ] = None,
) -> "capo_geo_places.types.geocode_response.GeocodeResponse":
    """<p> <code>Geocode</code> 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 <code>ap-southeast-1</code> and <code>ap-southeast-5</code> regions for <a href="https://docs.aws.amazon.com/location/latest/developerguide/GrabMaps.html">GrabMaps</a> customers.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/location/latest/developerguide/geocode.html">Geocode</a> in the <i>Amazon Location Service Developer Guide</i>.</p>

    Args:
        query_text: <p>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.</p>
        max_results: <p>An optional limit for the number of results returned in a single call.</p> <p>Default value: 20</p>
        bias_position: <p>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 <code>[lng, lat]</code> and in the WGS 84 format.</p>
        filter: <p>A structure which contains a set of inclusion/exclusion properties that results must possess in order to be returned as a result.</p>
        additional_features: <p>A list of optional additional parameters, such as time zone, that can be requested for each result.</p>
        language: <p>A list of <a href="https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry">BCP 47</a> 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.</p>
        political_view: <p>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.</p>
        intended_use: <p> Indicates if the query results will be persisted in customer infrastructure. Defaults to <code>SingleUse</code> (not stored). Not supported in <code>ap-southeast-1</code> and <code>ap-southeast-5</code> regions for <a href="https://docs.aws.amazon.com/location/latest/developerguide/GrabMaps.html">GrabMaps</a> customers. </p> <note> <p>When storing <code>Geocode</code> responses, you <i>must</i> set this field to <code>Storage</code> to comply with the terms of service. These requests will be charged at a higher rate. Please review the <a href="https://aws.amazon.com/location/sla/">user agreement</a> and <a href="https://aws.amazon.com/location/pricing/">service pricing structure</a> to determine the correct setting for your use case.</p> </note>
        key: <p>Optional: The API key to be used for authorization. Either an API key or valid SigV4 signature must be provided when making a request.</p>
        postal_code_mode: <p>The <code>PostalCodeMode</code> 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 <code>EnumerateSpannedLocalities</code>, all cities in that postal code are returned. If it's populated with the value <code>EnumerateSpannedDistricts</code>, all combinations of the postal code with the corresponding district and city names are returned.</p>
        address_translations: <p>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 <code>District</code>, <code>Locality</code>, <code>Region</code>, and <code>SubRegion</code>.</p>
        address_names_mode: <p>Specifies how address names are returned. If not set, the service returns normalized (official) names by default. When set to <code>Matched</code>, address names in the response are based on the input query rather than official names. When set to <code>Administrative</code>, the service returns the official administrative names for address components. <code>Administrative</code> currently applies only to addresses in the United States.</p>

    Raises:
        capo_geo_places.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this action.</p>
        capo_geo_places.errors.internal_server_exception.InternalServerException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
        capo_geo_places.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling.</p>
        capo_geo_places.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by an AWS service.</p>
        capo_geo_places.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_geo_places.types.geocode_request.GeocodeRequest]",
    ) -> AsyncOperationResponse[
        "capo_geo_places.types.geocode_response.GeocodeResponse"
    ]:
        import capo_geo_places._operations.places_service.geocode

        (
            output,
            http_response,
        ) = await capo_geo_places._operations.places_service.geocode.async_geocode(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_geo_places.types.geocode_request.GeocodeRequest",
    ) -> dict[str, Any]:
        import capo_geo_places.types.geocode_request

        return capo_geo_places.types.geocode_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_geo_places.types.geocode_response.GeocodeResponse",
    ) -> dict[str, Any]:
        import capo_geo_places.types.geocode_response

        return capo_geo_places.types.geocode_response.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "Geocode", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_geo_places.types.geocode_request.GeocodeRequest = {}
    if query_text is not None:
        input_["query_text"] = query_text
    if query_components is not None:
        input_["query_components"] = query_components
    if max_results is not None:
        input_["max_results"] = max_results
    if bias_position is not None:
        input_["bias_position"] = bias_position
    if filter is not None:
        input_["filter"] = filter
    if additional_features is not None:
        input_["additional_features"] = additional_features
    if language is not None:
        input_["language"] = language
    if political_view is not None:
        input_["political_view"] = political_view
    if intended_use is not None:
        input_["intended_use"] = intended_use
    if key is not None:
        input_["key"] = key
    if postal_code_mode is not None:
        input_["postal_code_mode"] = postal_code_mode
    if address_translations is not None:
        input_["address_translations"] = address_translations
    if address_names_mode is not None:
        input_["address_names_mode"] = address_names_mode

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output