本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
如何完成地址
Autocomplete API 可讓您完成部分輸入的地址,為最終使用者提供標準化輸入,並提高資料輸入期間的效率。
潛在的使用案例
-
在結帳時填寫地址:當客戶輸入結帳表單時,促進準確且快速的地址輸入。
-
國家特定地址完成:將建議限制在特定國家/地區,以確保合規性或與使用者位置的相關性。
範例
在此範例中,會傳回最少的資料,以保持回應簡潔且符合成本效益。稍後可以使用 PlaceId 搭配 GetPlace API 擷取完整的位置詳細資訊。
- Sample request
-
{ "QueryText": "100 McCullum Rd" }
- Sample response
-
{ "ResultItems": [ { "PlaceId": "<Redacted>", "PlaceType": "PointAddress", "Title": "United Kingdom, E3 5JB, London, 100 McCullum Road" } ], "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" }'
- AWS CLI
-
aws geo-places autocomplete --key ${YourKey} --query-text "100 McCullum Rd"
此範例會傳回多個地址建議,允許使用者選取標準化地址格式,以準確填入表單欄位。
- Sample request
-
{ "QueryText": "100 McCullum Rd", "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", "AdditionalFeatures": [ "Core" ] }'
- AWS CLI
-
aws geo-places autocomplete --key ${YourKey} --query-text "100 McCullum Rd" --additional-features "Core"
使用自動完成
如何使用篩選條件完成地址