现在公司有一个新的需求,前端传入经纬度,后端计算出附近的医院、派出所等等,通过查阅高德地图的Web服务开发文档,找到了以下接口:
https://restapi.amap.com/v3/place/around?location=经纬度&key=web服务类型的key&keywords=派出所&types=130501&radius=5000&offset=20&page=1
参数 | |
---|---|
location | 逗号分割的经纬度,例如117.167688,27.469837 |
key | 创建的web类型的key 点击跳转去申请key |
keywords | 周边搜索的关键词 |
types | 检索目标的分类(POI类型) 参考高德API官方文档 |
radius | 查询半径 0-50000 |
offset | 每一页返回查询结果的个数 |
page | 第几页 |
{
"status": "1",
"info": "OK",
"infocode": "10000",
"count": "1",
"suggestion": {
"keywords": [],
"cities": []
},
"pois": [
{
"id": "B025705MII",
"parent": [],
"childtype": [],
"name": "止马镇中心卫生院",
"type": "医疗保健服务;综合医院;卫生院",
"typecode": "090102",
"biz_type": [],
"address": "止马镇止马中路1号",
"location": "117.169901,27.471023",
"tel": "0599-7771221;0599-7772778",
"pname": "福建省",
"cityname": "南平市",
"adname": "光泽县",
"importance": [],
"shopid": [],
"shopinfo": "2",
"poiweight": [],
"distance": "255",
"biz_ext": {
"rating": [],
"cost": []
},
"photos": [
{
"title": [],
"url": "http://store.is.autonavi.com/showpic/beceaa81b666376821c4c7819160742a"
}
]
}
]
}
这里的HttpUtils和JSONObject都是Hutools工具包的,大家可以直接引入Hutools即可
String resultStr = HttpUtils.get("https://restapi.amap.com/v3/place/around?location=" + location + "&key=你的key&keywords=派出所&types=130501&radius=5000&offset=20&page=1");
JSONObject resultJson = JSONObject.parseObject(resultStr);
JSONArray pois = resultJson.getJSONArray("pois");
String tel = pois.getJSONObject(0).getString("tel");
String name= pois.getJSONObject(0).getString("name");
String location= pois.getJSONObject(0).getString("location");