【发布时间】:2020-05-14 07:28:13
【问题描述】:
我正在使用Mapbox Geocoding API 来查找用户输入提供的地点的纬度和经度。这很好用。我还想显示该位置所在城市的名称。
这是一个示例请求,它搜索“70176”,德国的邮政编码:
https://api.mapbox.com/geocoding/v5/mapbox.places/70176.json?fuzzyMatch=true&language=en&access_token=redacted
这就是答案:
{
"type":"FeatureCollection",
"query":[
"70176"
],
"features":[
{
"id":"postcode.12480061547829920",
"type":"Feature",
"place_type":[
"postcode"
],
"relevance":1,
"properties":{
},
"text_en":"70176",
"place_name_en":"70176, Stuttgart, Baden-Württemberg, Germany",
"text":"70176",
"place_name":"70176, Stuttgart, Baden-Württemberg, Germany",
[...]
}
如您所见,它确实提供了包含城市(“斯图加特”)的完整地址,但它没有分开。您可以通过在查询中包含 &types=place 来指定您只查找城市,但它也只接受城市名称作为输入。
如何在不进行两次 API 调用的情况下获取纬度、经度和城市名称?
【问题讨论】: