首页 > 解决方案 > Mapbox API:如何获取给定邮政编码下的地址列表?

问题描述

正如问题一样 - 我有一个给定的邮政编码,我需要使用 Mapbox API 获取地址列表

请求以下端点后:

`https://api.mapbox.com/geocoding/v5/mapbox.places/${postcode}.json?types=postcode&access_token=${mapboxToken}`

我得到以下回复:

[
   {
      "id":"postcode.17660822408923720",
      "type":"Feature",
      "place_type":[
         "postcode"
      ],
      "relevance":1,
      "properties":{
         
      },
      "text":"HP1 3EN",
      "place_name":"HP1 3EN, Hemel Hempstead, Hertfordshire, England, United Kingdom",
      "matching_text":"HP13EN",
      "matching_place_name":"HP13EN, Hemel Hempstead, Hertfordshire, England, United Kingdom",
      "bbox":[
         -0.489006,
         51.760773,
         -0.487601,
         51.761635
      ],
      "center":[
         -0.488395,
         51.7610944
      ],
      "geometry":{
         "type":"Point",
         "coordinates":[
            -0.488395,
            51.7610944
         ]
      },
      "context":[
         {
            "id":"place.15727584894798730",
            "wikidata":"Q3532",
            "text":"Hemel Hempstead"
         },
         {
            "id":"district.8002140812776250",
            "wikidata":"Q3410",
            "text":"Hertfordshire"
         },
         {
            "id":"region.13483278848453920",
            "wikidata":"Q21",
            "short_code":"GB-ENG",
            "text":"England"
         },
         {
            "id":"country.12405201072814600",
            "wikidata":"Q145",
            "short_code":"gb",
            "text":"United Kingdom"
         }
      ]
   }
]

在此响应中,没有关于给定邮政编码下的地址的任何信息。

当我在 URL 查询中指定“地址”类型时,它会得到一个空数组作为响应。

`https://api.mapbox.com/geocoding/v5/mapbox.places/${postcode}.json?types=address&access_token=${mapboxToken}`

我在Mapbox 文档中找不到帮助,有人可以帮我解决这个问题吗?

标签: javascriptmapboxmapbox-gl-js

解决方案


听起来您正在尝试获取给定邮政编码中每个地址的列表?你不能用 Mapbox 做到这一点。

我怀疑您会找到任何允许您执行此操作的地理编码服务。


推荐阅读