

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

# 如何使用郵遞區號對地址號碼進行地理編碼
<a name="how-to-geocode-address-postal-code"></a>

在郵遞區號高度具體的國家/地區 （在同一街道上只連結幾個地址），只能使用門牌號碼和郵遞區號找到地址。此實務在運輸和包裹交付物流中很常見。加拿大、英國、荷蘭、美國 (ZIP\+4)、以色列、愛爾蘭和新加坡支援此功能。在愛爾蘭和新加坡，郵遞區號會提供確切的位置詳細資訊，向下到特定的門牌號碼。

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

### 使用郵遞區號對地址進行地理編碼
<a name="geocode-postal-code-example1"></a>

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

使用查詢元件

```
{
  "QueryComponents": {
    "AddressNumber": "1368",
    "PostalCode": "V5N 1T2"
  }
}
```

使用任意文字

```
{
  "QueryText": "1368, V5N1T2"
}
```

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

```
{
    "ResultItems": [
        {
            "PlaceId": "<Redacted>",
            "PlaceType": "PointAddress",
            "Title": "1368 E 8th Ave, Vancouver, BC V5N 1T2, Canada",
            "Address": {
                "Label": "1368 E 8th Ave, Vancouver, BC V5N 1T2, Canada",
                "Country": {
                    "Code2": "CA",
                    "Code3": "CAN",
                    "Name": "Canada"
                },
                "Region": {
                    "Code": "BC",
                    "Name": "British Columbia"
                },
                "SubRegion": {
                    "Name": "Metro Vancouver"
                },
                "Locality": "Vancouver",
                "District": "Grandview-Woodland",
                "PostalCode": "V5N 1T2",
                "Street": "E 8th Ave",
                "StreetComponents": [
                    {
                        "BaseName": "8th",
                        "Type": "Ave",
                        "TypePlacement": "AfterBaseName",
                        "TypeSeparator": " ",
                        "Prefix": "E",
                        "Language": "en"
                    }
                ],
                "AddressNumber": "1368"
            },
            "Position": [
                -123.07612,
                49.26306
            ],
            "MapView": [
                -123.0775,
                49.26216,
                -123.07474,
                49.26396
            ],
            "AccessPoints": [
                {
                    "Position": [
                        -123.07611,
                        49.26333
                    ]
                }
            ],
            "MatchScores": {
                "Overall": 1,
                "Components": {
                    "Address": {
                        "PostalCode": 1,
                        "AddressNumber": 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 '{
  "QueryComponents": {
    "AddressNumber": "1368",
    "PostalCode": "V5N 1T2"
  }
}'
```

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

```
aws geo-places geocode --key ${YourKey} --query-components '{"AddressNumber" : "1368", "PostalCode": "V5N 1T2"}'
```

------

### 在新加坡和愛爾蘭使用郵遞區號對地址進行地理編碼
<a name="geocode-postal-code-example2"></a>

在愛爾蘭，Eircode 系統會為每個家庭和企業指派唯一代碼，而在新加坡，郵遞區號同樣特定。在這兩個國家/地區，郵遞區號可以單獨識別確切的地址：不需要街道名稱、城市或住家號碼。
+ 新加坡：6 位數郵遞區號
+ 愛爾蘭：7 個字元的 Eircode

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

使用查詢元件

```
{
  "QueryComponents": {
    "PostalCode": "D02 X285"
  }
}
```

使用任意文字

```
{
  "QueryText": "D02 X285"
}
```

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

```
{
    "ResultItems": [
        {
            "PlaceId": "<Redacted>",
            "PlaceType": "PointAddress",
            "Title": "29-31 Adelaide Road, Dublin, County Dublin, D02 X285, Ireland",
            "Address": {
                "Label": "29-31 Adelaide Road, Dublin, County Dublin, D02 X285, Ireland",
                "Country": {
                    "Code2": "IE",
                    "Code3": "IRL",
                    "Name": "Ireland"
                },
                "SubRegion": {
                    "Code": "D",
                    "Name": "County Dublin"
                },
                "Locality": "Dublin",
                "District": "Dublin 2",
                "PostalCode": "D02 X285",
                "Street": "Adelaide Road",
                "StreetComponents": [
                    {
                        "BaseName": "Adelaide",
                        "Type": "Road",
                        "TypePlacement": "AfterBaseName",
                        "TypeSeparator": " ",
                        "Language": "en"
                    }
                ],
                "AddressNumber": "29-31"
            },
            "Position": [
                -6.25549,
                53.33207
            ],
            "MapView": [
                -6.257,
                53.33117,
                -6.25398,
                53.33297
            ],
            "AccessPoints": [
                {
                    "Position": [
                        -6.25536,
                        53.33231
                    ]
                }
            ],
            "MatchScores": {
                "Overall": 1,
                "Components": {
                    "Address": {
                        "PostalCode": 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 '{
  "QueryComponents": {
    "PostalCode": "D02 X285"
  }
}'
```

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

```
aws geo-places geocode --key ${YourKey} --query-components '{"PostalCode": "V5N 1T2"}'
```

------

## 開發人員秘訣
<a name="geocode-postal-code-dev-tips"></a>

進一步了解 [ZIP\+4](https://en.wikipedia.org/wiki/ZIP_Code#ZIP+4) （美國） 和 [ Eircode](https://en.wikipedia.org/wiki/Postal_addresses_in_the_Republic_of_Ireland) （愛爾蘭）。此外，了解加拿大、英國、荷蘭、新加坡和以色列的郵遞區號系統。