

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

# 使用“建议”选择路线，并能够突出显示匹配的查询词
<a name="suggest-highlight-matched-query-terms"></a>

借助建议 API，当键入针对地点或类别的搜索查询时，用户会获得实时的自动补全建议。结果按相关性进行排序，最有可能的匹配项排在最前面。该 API 响应包含一些突出显示的信息，说明每条建议与用户查询的匹配情况。

## 潜在使用案例
<a name="suggest-disambiguate-results-potential-use"></a>

使用突出显示功能向用户显示每条建议的哪些部分与他们的输入内容相匹配，从而便于用户快速选择所需的结果。

## 示例
<a name="suggest-hightlight-results-examples"></a>

向用户显示结果列表时，响应中的**突出显示**字段可用于帮助用户识别输入与结果的匹配情况。在下面的示例中，用户查询“Effel tow”。这与**标题**“Tour Eiffel（Eiffel Tower）”的结果相符。使用“突出显示结果”字段，可以设置结果样式，以显示输入查询与输出结果的匹配之处，最终向用户显示的文本为“Tour Eiffel（**Eiffel Tow**er）”。

### 使用建议 API 突出显示查询结果
<a name="suggest-hightlight-example"></a>

此示例演示如何使用建议 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"
```

------

## 开发人员提示
<a name="suggest-highlight-developer-tips"></a>

使用 `Title` 响应字段显示搜索结果，为用户提供简洁、可识别的条目。对于可能看起来相似的结果，请使用 `Place.Address.Label` 字段显示额外的地址详细信息，以帮助用户进行区分。有关更多信息，请参阅 [如何帮助用户消除相似结果之间的歧义使用建议 API 消除结果的歧义](suggest-disambiguate-results.md)。