

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

# 如何使用地理空间上下文进行地理编码
<a name="how-to-geocode-geospatial"></a>

地理编码 API 允许您使用地理空间上下文（例如偏差位置）来获取所需的结果。

**注意**  
“偏差位置”是指一种根据用户的指定位置或定义区域，对搜索结果进行优先级排序的机制。它本质上是将搜索结果的焦点转向在地理上距离指定偏差点更近的地点，不一定排除其他结果。

## 潜在用途
<a name="geospatial-uses"></a>

根据您的业务需求，使用地理空间上下文获取正确的结果。

## 示例
<a name="geospatial-examples"></a>

### 使结果偏向某个位置
<a name="bias-position-example"></a>

通过偏向某个位置，您可以更改结果的排名。尝试以下示例，先使用 `BiasPosition` 值，然后不使用该值，对结果进行比较。

------
#### [ Sample request ]

```
{
    "QueryText": "George Street",
    "BiasPosition": [
                151.2059,
                -33.8691
            ]
}
```

------
#### [ Sample response ]

```
{
    "ResultItems": [
        {
            "PlaceId": "<Redacted>",
            "PlaceType": "Street",
            "Title": "George St, Sydney NSW, Australia",
            "Address": {
                "Label": "George St, Sydney NSW, Australia",
                "Country": {
                    "Code2": "AU",
                    "Code3": "AUS",
                    "Name": "Australia"
                },
                "Region": {
                    "Code": "NSW",
                    "Name": "New South Wales"
                },
                "Locality": "Sydney",
                "Street": "George St",
                "StreetComponents": [
                    {
                        "BaseName": "George",
                        "Type": "St",
                        "TypePlacement": "AfterBaseName",
                        "TypeSeparator": " ",
                        "Language": "en"
                    }
                ]
            },
            "Position": [
                151.20691,
                -33.86974
            ],
            "Distance": 117,
            "MapView": [
                151.20225,
                -33.88406,
                151.20912,
                -33.85635
            ],
            "MatchScores": {
                "Overall": 1,
                "Components": {
                    "Address": {
                        "Intersection": [
                            1
                        ]
                    }
                }
            }
        },
        ...
        ...
    ]
}
```

------
#### [ cURL ]

```
curl --request POST \
  --url 'https://places.geo.eu-central-1.amazonaws.com/v2/geocode?key=Your_Key' \
  --header 'Content-Type: application/json' \
  --data '{
  "QueryText": "George Street",
    "BiasPosition": [
                151.2059,
                -33.8691
            ]
}'
```

------
#### [ AWS CLI ]

```
aws geo-places geocode --key ${YourKey} --query-text "George Street" --bias-position 151.2059 -33.8691
```

------

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

对于地址地理编码，请尽量使用完整的地址，或使用带有偏差位置组合（包括国家/地区和地点）的查询组件。要了解更多信息，请参阅[如何对地址进行地理编码](how-to-geocode-address.md)。