百度地图根据经纬度得到地理位置

String url = "http://api.map.baidu.com/geocoder/v2/?ak=2uZgkxkTV4BCdGfAWN6m3cra&callback=renderReverse&location=39.983424,116.322987&output=json&pois=0";
URL getUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));//设置
String result = reader.readLine();
JSONObject json = JSONObject.fromObject(result);
String address= json.getString("result");
json = JSONObject.fromObject(address);
address = json.getString("formatted_address");
System.out.println(address);

 

posted @ 2014-09-12 16:40  箜篌  阅读(505)  评论(0编辑  收藏  举报