mapbox 地理编码 API 响应中缺少 short_code(对于美国境内的某个区域)

short_code is missing (for a region in US territory) in mapbox geocoding API response

我们需要

short_code 才能将 region/location 名称翻译成邮政编码。我们能够使用 mapbox 地理编码 API 获得丹佛地区的 short_code。但是,short_code Cayey(波多黎各领土内的地区)在同一个 API 响应中 缺失 。请在下面的合同中查看更多详细信息。

另一个观察结果是 Cayey 所在的国家/地区显示为波多黎各而不是美国。

https://api.mapbox.com/geocoding/v5/mapbox.places/denver.json?access_token={{token}}&autocomplete=true&country=US&types=region,district,place,locality&limit=20

'denver' 的 Mapbox geocodong 响应:

{
  "context": [
    {
      "id": "region.10002699958017490",
      "wikidata": "Q1261",
      "short_code": "US-CO",
      "text": "Colorado"
    },
    {
      "id": "country.19678805456372290",
      "wikidata": "Q30",
      "short_code": "us",
      "text": "United States"
    }
  ]
}

https://api.mapbox.com/geocoding/v5/mapbox.places/cayey.json?access_token={{token}}&autocomplete=true&country=US&types=region,district,place,locality&limit=20

'Cayey' 的 Mapbox 地理编码响应:

    {
      "context": [
        {
          "id": "region.11316909078893780",
          "wikidata": "Q2307508",
          "text": "Cayey"
        },
        {
          "id": "country.16776721557498950",
          "wikidata": "Q1183",
          "short_code": "pr",
          "text": "Puerto Rico"
        }
      ]
    }

mapbox 团队可以在这方面帮助我吗?

正如 document 所解释的那样,short_code 是可选的。因此,不能保证它始终包含在内。

Yoshikage Ochi 的回答是正确的:short_code 是一个可选的 属性,并不总是包含在 Mapbox Geocoding API response object.

特定于您的波多黎各示例:有一些区域不遵守 ISO 3166-1 中的“规则”。他们被认为是 countries and/or subdivisions。波多黎各是其中之一,没有指定 ISO 3166-2 regions/provinces。由于波多黎各内的要素没有 ISO 3166-2 代码,因此无法在 Mapbox 地理编码 API 响应中包含要素 Cayey 的 short_code。

在 ISO 标准中,波多黎各被视为一个国家,因为它有一个 ISO 3166-1 指定代码“pr”。由于它被视为国家/地区,因此“short_code”:“我们”不会出现在国家/地区上下文中。