0
votes

short_code is required for us to translate a region/location name to zip codes. We are able to get the short_code for denver region using mapbox geocoding API. However, short_code for Cayey(region in Puerto Rico territory) is missing in the same API response. Please see more details in the contract below.

Another observation is that the country for Cayey is shown as Puerto Rico instead of US.

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

Mapbox geocodong response for 'denver':

{
  "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

Mapbox geocoding response for 'Cayey':

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

Could mapbox team help me in this regard?

2

2 Answers

1
votes

Yoshikage Ochi's answer is correct: short_code is an optional property that is not always included in the Mapbox Geocoding API response object.

Specific to your Puerto Rico example: There are a handful of areas that don’t play by the “rules” in ISO 3166-1. They are considered countries and/or subdivisions. Puerto Rico is one of those areas, which don't have ISO 3166-2 specified regions/provinces. As there is no ISO 3166-2 code for features within Puerto Rico, it isn't possible to include a short_code for the feature Cayey in the Mapbox Geocoding API response.

In the ISO standard, Puerto Rico is treated as a country, since it has an ISO 3166-1 assigned code "pr". As it is treated as a country, "short_code": "us" would not be in the country context.

2
votes

As the document explains, short_code is optional. Therefore, it's not guaranteed it's always included.