1.申请高德地图key
2.逆地理编码(坐标->地址)-地理X:
https://lbs.amap.com/demo/jsapi-v2/example/geocoder/regeocoding
3.经纬度在线查询网址:https://map.jiqrxx.com/jingweidu/
4.高德地图API资料地址:https://lbs.amap.com/api/webservice/guide/api/georegeo
5.高德地图响应错误码文档地址:https://lbs.amap.com/api/webservice/guide/tools/info
/**
*根据经纬度获取省市区
*/
public static String getAddressStr(String log, String lat){
//lat 小 log 大
//参数解释: 纬度,经度 采用高德API可参考高德文档https://lbs.amap.com/
//注意key是在高德开放平台申请的key,具体获得key的步骤请查看网址:https://developer.amap.com/api/webservice/guide/create-project/get-key
String key = "个人申请的高德地图key";
String parameters="?key="+key;
// parameters+="&location="+"116.481488,39.990464";
parameters+="&location="+log+","+lat;//经纬度坐标
parameters+="&extensions=true";//返回结果控制,extensions 参数取值为 all 时会返回基本地址信息、附近 POI 内容、道路信息以及道路交叉口信息。
parameters+="&radius=10";//搜索半径,radius取值范围在0~3000,默认是1000。单位:米
parameters+="&batch=false";//批量查询控制,batch 参数设置为 false 时进行单点查询,此时即使传入多个经纬度也只返回第一个经纬度的地址解析查询结果。
parameters+="&roadlevel=0";//道路等级,当 roadlevel = 0 时,显示所有道路
// String urlString = "https://restapi.amap.com/v3/geocode/regeo?location="+lat+","+log+"&extensions=base&batch=false&roadlevel=0&key="+key;
String urlString = "https://restapi.amap.com/v3/geocode/regeo"+parameters;
StringBuilder res = new StringBuilder();
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
res.append(line).append("\n");
}
in.close();
//解析结果
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(res.toString());
System.out.println("jsonObject = " + jsonObject);
com.alibaba.fastjson.JSONObject jsonObject1 = jsonObject.getJSONObject("regeocode");
res = new StringBuilder(jsonObject1.getString("formatted_address"));
} catch (Exception e) {
System.out.println("获取地址信息异常");
e.printStackTrace();
return null;
}
System.out.println("通过API获取到具体位置:"+res);
return res.toString();
}