我想结合两个或更多API的响应。我之前没有制作过API,所以我更喜欢在线提供两种API的方法
例如,如果一个API列出了加利福尼亚州的城市名称和德克萨斯州的其他城市名称,那么我如何才能以一种API调用返回加州和德克萨斯城市列表的方式将它们组合在一起?
你们知道这样的东西是否可以上网吗?像任何工具或什么?
在此先感谢您的帮助
我想要以下结构或具有以下结构的API。任何具有这种结构的API都很好,它应该有一系列的位置
results:
[
California :
{
county:Orange county
lat:
long:
},
{
county:santa clara county
lat:
long:
},
{
county:LA county
lat:
long:
},
{
county:long beach county
lat:
long:
},
],
Texas:
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
],
New Jersey[
{
county:Orange county
lat:
long:
}
]
]
答案 0 :(得分:0)
可以通过在开发控制台中使用javascript对openstreetmaps发出两个请求,或者在<script>
标记中,也可以使用curl
或python
和{ {1}},或者您喜欢的任何语言:
requests.get
输出:
Promise.all([
fetch("http://nominatim.openstreetmap.org/search/?city=San%20Francisco&state=California&format=json"),
fetch("http://nominatim.openstreetmap.org/search/?city=Austin&state=Texas&format=json")
])
.then(values => {
return Promise.all(values.map(v=>v.text()))
})
.then(values => {
values.map(v=>{console.log(v)})
})
.catch(e => {console.warn(e)})
另一种选择是使用:
docs中的示例:
"[
{
"place_id": "158675742",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
"osm_type": "relation",
"osm_id": "111968",
"boundingbox": [
"37.6403143",
"37.9298443",
"-123.1738249",
"-122.2817799"
],
"lat": "37.7792808",
"lon": "-122.4192362",
"display_name": "San Francisco, San Francisco City and County, California, United States of America",
"class": "place",
"type": "city",
"importance": 0.99836369596997,
"icon": "http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"
}
]"
"[
{
"place_id": "158900509",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
"osm_type": "relation",
"osm_id": "113314",
"boundingbox": [
"30.0986648",
"30.516863",
"-97.9383829",
"-97.5614889"
],
"lat": "30.2711286",
"lon": "-97.7436994",
"display_name": "Austin, Travis County, Texas, United States of America",
"class": "place",
"type": "city",
"importance": 0.8589403884382,
"icon": "http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"
}
]"
对于swift,看起来这可能有用,但它只是一个get请求,所以我不确定openstreetmap的包装器有多复杂:
或参见: