如何使用过滤器完成地址 - Amazon Location Service

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

如何使用过滤器完成地址

Autocomplete API 使您能够完成部分输入的地址,从而便于最终用户快速、标准化地输入地址。通过使用AdditionalFeatures参数,您可以自定义响应中提供的信息以满足特定要求。

潜在用例

  • 最大限度地减少数据以提高成本效益:在预计会有后续查询时,仅请求必要的地址组件,从而减少响应规模和数据传输成本。

  • 包括必要的详细信息以供直接使用:检索全面的地址信息,无需进行其他查询。

示例

此示例应用国家/地区筛选器来优化结果,从而使用户输入的地址的标准化格式能够准确填充表单字段。

Sample request
{ "QueryText": "100 McCullum Rd", "Filter": { "IncludeCountries": [ "GBR" ] } }
Sample response
{ "ResultItems": [ { "PlaceId": "<Redacted>", "PlaceType": "PointAddress", "Title": "United Kingdom, E3 5JB, London, 100 McCullum Road", "Address": { "Label": "100 McCullum Road, London, E3 5JB, United Kingdom", "Country": { "Code2": "GB", "Code3": "GBR", "Name": "United Kingdom" }, "Region": { "Name": "England" }, "SubRegion": { "Code": "LDN", "Name": "London" }, "Locality": "London", "District": "Bow", "PostalCode": "E3 5JB", "Street": "McCullum Road", "StreetComponents": [ { "BaseName": "McCullum", "Type": "Road", "TypePlacement": "AfterBaseName", "TypeSeparator": " ", "Language": "en" } ], "AddressNumber": "100" }, "Language": "en", "Highlights": { "Title": [ { "StartIndex": 32, "EndIndex": 35, "Value": "100" }, { "StartIndex": 36, "EndIndex": 49, "Value": "McCullum Road" } ], "Address": { "Label": [ { "StartIndex": 0, "EndIndex": 3, "Value": "100" }, { "StartIndex": 4, "EndIndex": 17, "Value": "McCullum Road" } ], "Street": [ { "StartIndex": 0, "EndIndex": 13, "Value": "McCullum Road" } ], "AddressNumber": [ { "StartIndex": 0, "EndIndex": 3, "Value": "100" } ] } } } ], "QueryRefinements": [] }
cURL
curl --request POST \ --url 'https://places.geo.eu-central-1.amazonaws.com/v2/autocomplete?key=Your_Key' \ --header 'Content-Type: application/json' \ --data '{ "QueryText": "100 McCullum Rd", "Filter": { "IncludeCountries": [ "GBR" ] } }'
AWS CLI
aws geo-places autocomplete --key ${YourKey} --query-text "100 McCullum Rd" \ --filter '{"IncludeCountries": ["GBR"]}'

此示例返回其他数据,允许在不进行后续查询的情况下使用返回的地址详细信息。对于这个用例来说,这Core组附加功能已经足够了。

Sample request
{ "QueryText": "100 McCullum Rd", "Filter": { "IncludeCountries": [ "GBR" ] }, "AdditionalFeatures": [ "Core" ] }
Sample response
{ "ResultItems": [ { "PlaceId": "<Redacted>", "PlaceType": "PointAddress", "Title": "United Kingdom, E3 5JB, London, 100 McCullum Road", "Address": { "Label": "100 McCullum Road, London, E3 5JB, United Kingdom", "Country": { "Code2": "GB", "Code3": "GBR", "Name": "United Kingdom" }, "Region": { "Name": "England" }, "SubRegion": { "Code": "LDN", "Name": "London" }, "Locality": "London", "District": "Bow", "PostalCode": "E3 5JB", "Street": "McCullum Road", "StreetComponents": [ { "BaseName": "McCullum", "Type": "Road", "TypePlacement": "AfterBaseName", "TypeSeparator": " ", "Language": "en" } ], "AddressNumber": "100" }, "Language": "en", "Highlights": { "Title": [ { "StartIndex": 32, "EndIndex": 35, "Value": "100" }, { "StartIndex": 36, "EndIndex": 49, "Value": "McCullum Road" } ], "Address": { "Label": [ { "StartIndex": 0, "EndIndex": 3, "Value": "100" }, { "StartIndex": 4, "EndIndex": 17, "Value": "McCullum Road" } ], "Street": [ { "StartIndex": 0, "EndIndex": 13, "Value": "McCullum Road" } ], "AddressNumber": [ { "StartIndex": 0, "EndIndex": 3, "Value": "100" } ] } } } ], "QueryRefinements": [] }
cURL
curl --request POST \ --url 'https://places.geo.eu-central-1.amazonaws.com/v2/autocomplete?key=Your_Key' \ --header 'Content-Type: application/json' \ --data '{ "QueryText": "100 McCullum Rd", "Filter": { "IncludeCountries": [ "GBR" ] }, "AdditionalFeatures": [ "Core" ] }'
AWS CLI
aws geo-places autocomplete --key ${YourKey} --query-text "100 McCullum Rd" \ --additional-features "Core" \ --filter '{"IncludeCountries": ["GBR"]}'