使用 Suggest 并能够筛选某个地区或国家 - Amazon Location Service

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

使用 Suggest 并能够筛选某个地区或国家

使用 Suggest API 可以完成对地点或结果类别的查询。结果按最有可能和不太可能的匹配项进行排序。此外,您还可以进一步筛选特定地区或国家的结果。

潜在用例

  • 筛选结果:执行搜索时,您可以按国家/地区进行筛选,也可以仅按业务所在地区进行筛选。

示例

添加按国家/地区筛选条件可确保您只收到最相关的结果。使用过滤器。 IncludeCountries 为此。

Sample request
{ "QueryText": "hote", "BiasPosition": [ 2.2982750966095398, 48.856078089325294 ], "Filter": { "IncludeCountries": [ "FRA" ] }, "AdditionalFeatures": [ "Core" ] }
Sample response
{ "ResultItems": [ { "Title": "Hôtel de Matignon (Hôtel Matignon)", "SuggestResultItemType": "Place", "Place": { "PlaceId": "Redacted", "PlaceType": "PointOfInterest", "Address": { "Label": "Hôtel de Matignon, 57 Rue de Varenne, 75007 Paris, France", "Country": { "Code2": "FR", "Code3": "FRA", "Name": "France" }, "Region": { "Code": "IDF", "Name": "Île-de-France" }, "SubRegion": { "Name": "Paris" }, "Locality": "Paris", "District": "7e Arrondissement", "PostalCode": "75007", "Street": "Rue de Varenne", "StreetComponents": [ { "BaseName": "Varenne", "Type": "Rue de", "TypePlacement": "BeforeBaseName", "TypeSeparator": " ", "Language": "fr" } ], "AddressNumber": "57" }, "Position": [ 2.32072, 48.85471 ], "Distance": 1650, "Categories": [ { "Id": "tourist_attraction", "Name": "Tourist Attraction", "LocalizedName": "Attraction touristique", "Primary": true }, { "Id": "landmark-attraction", "Name": "Landmark-Attraction", "LocalizedName": "Lieu d'intérêt/Attraction", "Primary": false }, { "Id": "historical_monument", "Name": "Historical Monument", "LocalizedName": "Monument historique", "Primary": false }, { "Id": "residential_area-building", "Name": "Residential Area-Building", "LocalizedName": "Bâtiment résidentiel", "Primary": false } ] }, "Highlights": { "Title": [ { "StartIndex": 0, "EndIndex": 4, "Value": "Hôt" }, { "StartIndex": 19, "EndIndex": 23, "Value": "(Hô" } ], "Address": { "Label": [ { "StartIndex": 0, "EndIndex": 4, "Value": "Hôt" } ] } } }, ... { "Title": "Hotel", "SuggestResultItemType": "Query", "Query": { "QueryId": "Redacted", "QueryType": "Category" }, "Highlights": { "Title": [ { "StartIndex": 0, "EndIndex": 4, "Value": "Hote" } ] } }, ... ], "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": "hote", "BiasPosition": [ 2.2982750966095398, 48.856078089325294 ], "Filter": { "IncludeCountries": [ "FRA" ] }, "AdditionalFeatures": [ "Core" ] }'
AWS CLI
aws geo-places suggest --key ${YourKey} \ --query-text "hote" \ --bias-position 2.2982750966095398 48.856078089325294 \ --filter '{"IncludeCountries": ["FRA"]}' \ --additional-features "Core"

为搜索添加 filter-by-region选项会将结果限制为仅显示符合所提供区域的搜索结果。这用于将搜索范围限制在与您的业务相关的区域。以下示例显示了对波士顿地区附近的万豪酒店的拼写错误搜索,其中包含一些酒店搜索结果和后续查询。

Sample request
{ "QueryText": "Mariot", "Filter": { "IncludeCountries": [ "USA" ], "BoundingBox": [ -71.15693983012913,42.261623506672635, -70.97249727163558,42.37584075627763 ] }, "AdditionalFeatures": [ "Core" ] }
Sample response
{ "ResultItems": [ { "Title": "Boston Marriott Copley Place", "SuggestResultItemType": "Place", "Place": { "PlaceId": "Redacted", "PlaceType": "PointOfInterest", "Address": { "Label": "Boston Marriott Copley Place, 110 Huntington Ave, Boston, MA 02116, United States", "Country": { "Code2": "US", "Code3": "USA", "Name": "United States" }, "Region": { "Code": "MA", "Name": "Massachusetts" }, "SubRegion": { "Name": "Suffolk" }, "Locality": "Boston", "District": "Back Bay", "PostalCode": "02116", "Street": "Huntington Ave", "StreetComponents": [ { "BaseName": "Huntington", "Type": "Ave", "TypePlacement": "AfterBaseName", "TypeSeparator": " ", "Language": "en" } ], "AddressNumber": "110" }, "Position": [ -71.07769, 42.34726 ], "Distance": 3347, "Categories": [ { "Id": "hotel", "Name": "Hotel", "LocalizedName": "Hotel", "Primary": true } ], "BusinessChains": [ { "Name": "Marriott", "Id": "Marriott" } ], "AccessPoints": [ { "Position": [ -71.07922, 42.34665 ] } ] }, "Highlights": { "Title": [ { "StartIndex": 7, "EndIndex": 14, "Value": "Marriot" } ], "Address": { "Label": [ { "StartIndex": 7, "EndIndex": 14, "Value": "Marriot" } ] } } }, ... { "Title": "Marriott", "SuggestResultItemType": "Query", "Query": { "QueryId": "Redacted", "QueryType": "BusinessChain" }, "Highlights": { "Title": [ { "StartIndex": 0, "EndIndex": 8, "Value": "Marriott" } ] } }, ... ], "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": "Mariot", "Filter": { "IncludeCountries": [ "USA" ], "BoundingBox": [ -71.15693983012913,42.261623506672635, -70.97249727163558,42.37584075627763 ] }, "AdditionalFeatures": [ "Core" ] }'
AWS CLI
aws geo-places suggest --key ${YourKey} \ --query-text "hote" \ --filter '{"IncludeCountries": ["FRA"], "BoundingBox": [ -71.15693983012913,42.261623506672635, -70.97249727163558,42.37584075627763]}' \ --additional-features "Core"

开发者小贴士

使用Title响应字段显示搜索结果,为用户提供简洁、可识别的条目。对于可能看起来相似的结果,请使用该Place.Address.Label字段显示其他地址详细信息,以帮助用户区分它们。有关更多信息,请参阅 如何帮助用户消除相似结果之间的歧义