本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用建議和反白顯示相符查詢詞彙的能力來選擇路由
使用建議 API,您可以在使用者輸入位置或類別的搜尋查詢時,取得即時自動完成建議。結果會依相關性排名,最可能的相符項目會先出現。API 回應包含反白資訊,顯示每個建議如何符合使用者的查詢。
潛在的使用案例
使用反白來向使用者顯示每個建議中的哪些部分符合他們的輸入,讓您更輕鬆地快速選取所需的結果。
範例
向使用者顯示結果清單時,回應中的醒目提示欄位可用來協助使用者識別輸入與結果的比對方式。在以下範例中,使用者會查詢「Effel tow」。這符合標題為 “Tour Eiffel (Eiffel Tower)” 的結果。使用醒目提示結果欄位,結果可以設計樣式以顯示輸入查詢與輸出的相符位置,導致向使用者顯示「Tour Eiffel (Eiffel Tow er)」的文字。
此範例示範如何使用建議 API 來查詢拼寫錯誤的興趣點。
- Sample request
-
{ "QueryText": "Effel tow", "Filter": { "Circle": { "Radius": 10000, "Center": [ 2.3431932014695382, 48.858844492141145 ] }, "IncludeCountries": [ "FRA" ] }, "AdditionalFeatures": [ "Core" ] } - Sample response
-
{ "ResultItems": [ { "Title": "Tour Eiffel (Eiffel Tower)", "SuggestResultItemType": "Place", "Place": { "PlaceId": "<Redacted>", "PlaceType": "PointOfInterest", "Address": { "Label": "Tour Eiffel, * Avenue Anatole France, ***** Paris, France", "Country": { "Code2": "FR", "Code3": "FRA", "Name": "France" }, "Region": { "Code": "IDF", "Name": "Île-de-France" }, "SubRegion": { "Name": "Paris" }, "Locality": "Paris", "District": "*e Arrondissement", "PostalCode": "*****", "Street": "Avenue Anatole France", "StreetComponents": [ { "BaseName": "Anatole France", "Type": "Avenue", "TypePlacement": "BeforeBaseName", "TypeSeparator": " ", "Language": "fr" } ], "AddressNumber": "5" }, "Position": [ 2.2945, 48.85824 ], "Distance": 3563, "Categories": [ { "Id": "historical_monument", "Name": "Historical Monument", "LocalizedName": "Monument historique", "Primary": true }, { "Id": "landmark-attraction", "Name": "Landmark-Attraction", "LocalizedName": "Lieu d'intérêt/Attraction", "Primary": false }, { "Id": "tourist_attraction", "Name": "Tourist Attraction", "LocalizedName": "Attraction touristique", "Primary": false }, { "Id": "sports_complex-stadium", "Name": "Sports Complex-Stadium", "LocalizedName": "Stade ou complexe sportif", "Primary": false } ] }, "Highlights": { "Title": [ { "StartIndex": 13, "EndIndex": 23, "Value": "Eiffel Tow" } ], "Address": {} } } ], "QueryRefinements": [] } - cURL
-
curl --request POST \ --url 'https://places.geo.eu-central-1.amazonaws.com/v2/suggest?key=Your_Key' \ --header 'Content-Type: application/json' \ --data '{ "QueryText": "Effel tow", "Filter": { "Circle": { "Radius": 10000, "Center": [ 2.3431932014695382, 48.858844492141145 ] }, "IncludeCountries": [ "FRA" ] }, "AdditionalFeatures": [ "Core" ] }' - AWS CLI
-
aws geo-places suggest --key ${YourKey} \ --query-text "Effel tow" \ --filter '{"Circle": {"Radius": 10000, "Center": [2.3431932014695382, 48.858844492141145]}, "IncludeCountries": ["FRA"]}' \ --additional-features "Core"
開發人員秘訣
使用Title回應欄位顯示搜尋結果,為使用者提供簡潔、可辨識的項目。對於可能看起來相似的結果,請使用 Place.Address.Label 欄位來顯示其他地址詳細資訊,以協助使用者區分它們。如需詳細資訊,請參閱如何協助使用者在類似結果之間模糊不清。
取得部分輸入或拼寫錯誤查詢的結果
篩選區域的結果