Java后台调用的高德api,通过经纬度查询地址信息
官方文档地址:https://lbs.amap.com/api/webservice/guide/api/georegeo
传入的参数为location,location:经度,纬度
输出为json字符串
/**
* 调用地图api,通过location查询areaAdcode
* @param params
* @return
* @throws Exception
*/
public static Map<String,String> findAdressByLocation(String location) throws Exception {
Map<String, String> resuleMap = new HashMap<>();
String areaAdcode = null;
String accessAddress = null;
String key ="3898**************94700";
String apiurl = "https://restapi.amap.com/v3/geocode/regeo?location="
+ location +"&poitype=&key="
+ key +"&radius=1000&extensions=all&batch=false&roadlevel=0";
String result = HttpUtils.httpsGetRequest(apiurl);
JSONObject jsonObj = new JSONObject().fromObject(result);
if(jsonObj.getInt("status") == 1){
JSONObject regeocodes = jsonObj.getJSONObject("regeocode");
JSONObject addressComponent = regeocodes.getJSONObject("addressComponent");
areaAdcode = addressComponent.getString("adcode");
accessAddress = regeocodes.getString("formatted_address");
resuleMap.put("areaAdcode", areaAdcode);//行政编码
resuleMap.put("accessAddress", accessAddress);//地址
}else{
resuleMap.put("areaAdcode", areaAdcode);
resuleMap.put("accessAddress", accessAddress);
resuleMap.put("code", "500");
resuleMap.put("message", "高德api查询异常!");
return resuleMap;
}
resuleMap.put("code", "200");
resuleMap.put("message", "调用高德api成功!");
return resuleMap;
}
版权声明:本文为z12345614a原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。