将地址转换为英语

使用 Address Validation API 时,您可以要求验证响应同时返回转换为英语的地址。如果您的系统需要在接收非英语地址时提供以英文拉丁字符表示的地址信息,请使用此功能。例如:

  • 您的公司可能会满足世界各地的发货请求,并使用英语和基于英语的拉丁字符将所有地址标准化。
  • 如果一个国家/地区使用的语言与所提供的地址的语言不同,您的商家可能会负责处理货物运往的国家/地区。

如何退回英语地址

如需请求对包含的等效英语部分进行地址验证,请在验证请求正文中添加以下内容:

languageOptions: { returnEnglishLatinAddress: "true" }.

以下示例在验证普拉多博物馆的地址时请求基于英语的组件:

curl -X POST -d '{
  "regionCode" : ["ES"],
  "addressLines": ["C. de Ruiz de Alarcón, 23, 28014 Madrid, Spain"],
  "languageOptions": {returnEnglishLatinAddress: true}
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: API_KEY' \
'https://addressvalidation.googleapis.com/v1:validateAddress'

响应会在 englishLatinAddress 字段中返回英语地址。如需了解详情,请参阅下面的地址转换示例。返回的本地语言地址的每个组成部分都会尽可能转换为英语。转换后的地址不能作为 API 输入重复使用。

englishLatinAddress 字段使用的 Address proto 与 address 字段相同,但存在以下例外情况:

地址转换的运作方式

Address Validation API 会对地址的每个组成部分应用英文换算。这意味着,系统会单独处理 administrative_arealocality 以及地址的其他组成部分。如需查看地址组成部分的列表,请参阅参考文档中的 AddressComponent

下图展示了地址 Calle Dueñas, 5, 41003 Sevilla, España 的英语转换效果。

已翻译的地址组成部分,包括“路线”“国家/地区”和“市行政区”

对于评估为英语转换的每个组件,该服务会使用以下部分中介绍的过程。

尽可能使用完整翻译的英语

某些地址组成部分可能有可用的完整翻译版本。例如,在西班牙语中表示的国家/地区 España 将被翻译为 Spain。在这种情况下,该服务使用英语版本。较大的地址组成部分(例如 countryadministrative_area_level_1)通常就属于这种情况。

如果没有英语,则使用当地语言的拉丁语

拉丁化表示通过转录将当地语言转换为拉丁字母。

  • 如果地址的本地语言使用拉丁字符集,且地址组成部分没有对应的英语字符,则服务会替换本地语言中非英语的字符。例如,Calle Dueñas 会变为 Calle Duenas,其中 ñ 替换为 n。
  • 如果地址的本地语言未使用基于拉丁的字符集,并且地址组成部分没有对应的英语版本,则服务会使用本地化版本的当地语言(如果有)。例如,日语转化会返回日语的罗马拼音。所有非英语、非拉丁字符都会替换为基于英文的拉丁字符。例如:3 丁目变为 3 丁。
    • 请注意,预览尚不支持日语
  • 如果该语言的拉丁化版本不可用,则组件将以当地语言返回。

替换非英语的拉丁字符

任何非英语的拉丁字符都将替换为与其对应的英语字符。例如,以下每个字符都将被替换为字符“o”:嗞、达、ó、ô、的过程中、以下、ö、ø、ṏ、ṑ、ṓ、ṓ、 and ṍ、ṏ、ṑ、ṓ、➘、ỏ、ợ、ợ、ợ、 ợ、ợ、可、 、 例如:

Calle de Ruiz de Alarcón 变为 Calle de Ruiz de Alarcon

地址转换示例

以下示例展示了对西班牙双子宫请求的验证响应,其中 englishLatinAddress 以粗体显示。此请求使用了输入的 languageOptions 参数中的字段 returnEnglishLatinAddress

"result": {
  "verdict": {
    "inputGranularity": "PREMISE",
    "validationGranularity": "PREMISE",
    "geocodeGranularity": "PREMISE",
    "addressComplete": true,
    "hasInferredComponents": true
  },
  "address": {
    "formattedAddress": "Calle Dueñas, 5, 41003 Sevilla, España",
    "postalAddress": {
      "regionCode": "ES",
      "languageCode": "es",
      "postalCode": "41003",
      "administrativeArea": "Sevilla",
      "locality": "Sevilla",
      "addressLines": [
        "C. Dueñas, 5"
      ]
    },
    "addressComponents": [
      {
        "componentName": {
          "text": "Calle Dueñas",
          "languageCode": "es"
        },
        "componentType": "route",
        "confirmationLevel": "CONFIRMED"
      },
      {
        "componentName": {
          "text": "5",
          "languageCode": "es"
        },
        "componentType": "street_number",
        "confirmationLevel": "CONFIRMED"
      },
      {
        "componentName": {
          "text": "41003"
        },
        "componentType": "postal_code",
        "confirmationLevel": "CONFIRMED"
      },
      {
        "componentName": {
          "text": "Sevilla",
          "languageCode": "es"
        },
        "componentType": "locality",
        "confirmationLevel": "CONFIRMED"
      },
      {
        "componentName": {
          "text": "España",
          "languageCode": "es"
        },
        "componentType": "country",
        "confirmationLevel": "CONFIRMED"
      },
      {
        "componentName": {
          "text": "Sevilla",
          "languageCode": "es"
        },
        "componentType": "administrative_area_level_2",
        "confirmationLevel": "CONFIRMED",
        "inferred": true
      }
    ]
  },
  "geocode": {
    "location": {
      "latitude": 37.394849,
      "longitude": -5.9893604
    },
    "plusCode": {
      "globalCode": "8C9P92V6+W7"
    },
    "bounds": {
      "low": {
        "latitude": 37.3948098,
        "longitude": -5.9894249
      },
      "high": {
        "latitude": 37.3948882,
        "longitude": -5.9893025
      }
    },
    "featureSizeMeters": 7.174035,
    "placeId": "ChIJzRDYbgRsEg0RDDgHlF80UoI",
    "placeTypes": [
      "premise"
    ]
  },
  "metadata": {
    "business": true,
    "residential": false
  },
  "englishLatinAddress": {
    "formattedAddress": "Calle Duenas, 5, 41003 Seville, Spain",
    "postalAddress": {
      "regionCode": "ES",
      "languageCode": "en",
      "postalCode": "41003",
      "administrativeArea": "Seville",
      "locality": "Seville",
      "addressLines": [
        "C. Duenas, 5"
      ]
    },
    "addressComponents": [
      {
        "componentName": {
          "text": "Calle Duenas",
          "languageCode": "es"
        },
        "componentType": "route",
      },
      {
        "componentName": {
          "text": "5",
          "languageCode": "es"
        },
        "componentType": "street_number",
      },
      {
        "componentName": {
          "text": "41003"
        },
        "componentType": "postal_code",
      },
      {
        "componentName": {
          "text": "Seville",
          "languageCode": "en"
        },
        "componentType": "locality",
      },
      {
        "componentName": {
          "text": "Spain",
          "languageCode": "en"
        },
        "componentType": "country",
      },
      {
        "componentName": {
          "text": "Seville",
          "languageCode": "en"
        },
        "componentType": "administrative_area_level_2",
        "inferred": true
      }
    ]
  }
},
"responseId": "e874d263-7d0d-413f-9213-119a784765ed"