

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 如何使用篩選條件進行地理編碼
<a name="how-to-geocode-filters"></a>

Geocode API 可讓您使用篩選條件來取得所需的結果。

## 潛在用途
<a name="geocode-filters-uses"></a>

使用篩選條件，根據您的業務需求限制結果。

## 範例
<a name="geocode-filters-examples"></a>

### 在國家/地區內限制結果
<a name="geocode-filter-country-example"></a>

指定 的值`IncludeCountries`，以在結果中傳回該國家/地區的值。

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

如果沒有 `IncludeCountries": ["USA"]`，Geocode API 將傳回 Vancouver、BC、加拿大。

```
{
  "QueryText": "Vancouver",
    "Filter" : {
        "IncludeCountries": ["USA"]
    }
}
```

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

```
{
    "ResultItems": [
        {
            "PlaceId": "<Redacted>",
            "PlaceType": "Locality",
            "Title": "Vancouver, WA, United States",
            "Address": {
                "Label": "Vancouver, WA, United States",
                "Country": {
                    "Code2": "US",
                    "Code3": "USA",
                    "Name": "United States"
                },
                "Region": {
                    "Code": "WA",
                    "Name": "Washington"
                },
                "SubRegion": {
                    "Name": "Clark"
                },
                "Locality": "Vancouver",
                "PostalCode": "98660"
            },
            "Position": [
                -122.67156,
                45.63248
            ],
            "MapView": [
                -122.77466,
                45.57714,
                -122.46451,
                45.69803
            ],
            "MatchScores": {
                "Overall": 1,
                "Components": {
                    "Address": {
                        "Locality": 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": "Vancouver",
    "Filter" : {
        "IncludeCountries": ["USA"]
    }
}'
```

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

```
aws geo-places geocode --key ${YourKey} --query-text "Vancouver" --filter '{"IncludeCountries": ["USA"]}'
```

------

### 使用位置類型篩選條件縮小結果範圍
<a name="geocode-filter-place-example"></a>

指定 的值`IncludePlaceTypes`，以傳回結果中該位置的值。

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

如果沒有 `IncludePlaceTypes": ["Street"]`，Geocode API 會傳回 Georgia，這是一個國家/地區。您可以使用 **CAN** 和 **USA** `"IncludeCountries"`的值新增 ，以進一步精簡結果，並比較結果。

```
{
  "QueryText": "Georgia",
    "Filter" : {
        "IncludePlaceTypes": ["Street"]
    }

}
```

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

```
{
    "ResultItems": [
        {
            "PlaceId": "<Redacted>",
            "PlaceType": "Street",
            "Title": "Georgia, Benito Juárez, CDMX, México",
            "Address": {
                "Label": "Georgia, Benito Juárez, CDMX, México",
                "Country": {
                    "Code2": "MX",
                    "Code3": "MEX",
                    "Name": "México"
                },
                "Region": {
                    "Code": "CDMX",
                    "Name": "Ciudad de México"
                },
                "SubRegion": {
                    "Name": "Ciudad de México"
                },
                "Locality": "Benito Juárez",
                "Street": "Georgia",
                "StreetComponents": [
                    {
                        "BaseName": "Georgia",
                        "Language": "es"
                    }
                ]
            },
            "Position": [
                -99.17754,
                19.38887
            ],
            "MapView": [
                -99.18133,
                19.38755,
                -99.17374,
                19.39016
            ],
            "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": "Georgia",
    "Filter" : {
        "IncludePlaceTypes": ["Street"]
    }

}'
```

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

```
aws geo-places geocode --key ${YourKey} --query-text "Georgia" --filter '{"IncludePlaceTypes": ["Street"]}'
```

------

## 開發人員秘訣
<a name="geocode-filters-developer-tips"></a>

針對地址地理編碼，請嘗試使用完整地址或查詢元件搭配偏差位置的組合，包括國家/地區和地點。如需進一步了解，請參閱[如何對地址進行地理編碼](how-to-geocode-address.md)。