根据经纬度获取地址(中文地址以及地址code)

public static void main(String[] args) {
// lat 39.97646
//log 116.3039 116.33032,39.91333
String add = getAdd("116.33032", "39.91333");
System.out.println("地址信息:"+add);
JSONObject jsonObject = JSONObject.fromObject(add);
JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("addrList"));
JSONObject j_2 = JSONObject.fromObject(jsonArray.get(0));
String allAdd = j_2.getString("admName");
String arr[] = allAdd.split(",");
System.out.println("省:"+arr[0]+"\n市:"+arr[1]+"\n区:"+arr[2]);
}
public static String getAdd(String log, String lat ){
//lat 小 log 大
//参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)
String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010";
String res = "";
try {
URL url = new URL(urlString);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
res += line+"\n";
}
in.close();
} catch (Exception e) {
System.out.println("error in wapaction,and e is " + e.getMessage());
}
System.out.println(res);
return res;
}

响应数据:
地址信息:{"queryLocation":[39.91333,116.33032],"addrList":[{"type":"poi","status":1,"name":"中国水利水电科学研究院结构材料研究所","id":"ANB000AA11HN","admCode":"110108","admName":"北京市,北京市,海淀区,","addr":"羊坊店","nearestPoint":[116.33035,39.91279],"distance":54.083}]}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿呆编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值