宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 解决办法
  3. 正文

java 根据经纬度获取百度地图地址

2021年1月4日 803点热度 0人点赞 0条评论

示例代码:

PrintWriter outprint = response.getWriter();

//String lat = "39.983424"; // 纬度
//String lng = "116.322987";  // 经度
String lng = request.getParameter("jingdu");
String lat = request.getParameter("weidu");
//outprint.print(lng + ";" + lat);

try {

    URL url = new URL("http://api.map.baidu.com/geocoder/v2/?ak=wPPxsfCtNFm4PqEV68jbDdjP7U4twstj&callback=renderReverse&location=" + lat + "," + lng + "&output=json&pois=1");
    HttpURLConnection ucon = (HttpURLConnection) url.openConnection();
    ucon.connect();

    InputStream in = ucon.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    String str = reader.readLine();
    //outprint.print(str);

    str = str.substring(str.indexOf("(") + 1, str.length() - 1);
    //outprint.print(str);

    JSONObject jsonObject = new JSONObject(str);
    String address = "";
    address = jsonObject.getJSONObject("result").getString("formatted_address");

    outprint.print(address);
    outprint.close();
    outprint = null;

} catch(Exception e) {
    e.printStackTrace();
}

原文连接:https://blog.csdn.net/qq_22860341/article/details/72772971

标签: 暂无
最后更新:2021年1月4日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2025 宇筱博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2