百度转换经纬度为地址

 1 /**
 2      * 通过百度转换经纬度为地址信息
 3      * 
 4      * @param longitude 经度
 5      * @param latitude 纬度
 6      * @param coordtype 坐标体系:<br/>
 7      *         <ul>
 8      *         <li>bd09ll    百度墨卡托坐标</li>
 9      *         <li>gcj02ll    国测局墨卡托坐标</li>
10      *         <li>wgs84ll    GPS经纬度</li>
11      *         </ul>
12      * @return 访问百度,获取到的地址信息(json格式)
13      */
14     public static DBObject requestRelLocacion(double longitude, double latitude, String coordtype){
15         return requestRelLocacion(String.valueOf(longitude), String.valueOf(latitude), coordtype);
16     }
17     
18     /**
19      * 通过百度转换经纬度为地址信息
20      * 
21      * @param longitude 经度
22      * @param latitude 纬度
23      * @param coordtype 坐标体系:<br/>
24      *         <ul>
25      *         <li>bd09ll    百度墨卡托坐标</li>
26      *         <li>gcj02ll    国测局墨卡托坐标</li>
27      *         <li>wgs84ll    GPS经纬度</li>
28      *         </ul>
29      * @return 访问百度,获取到的地址信息(json格式)
30      */
31     public static DBObject requestRelLocacion(String longitude, String latitude, String coordtype){
32         DBObject retJson = null;
33         String requstUrl = "http://api.map.baidu.com/geocoder/v2/?ak=7049808f066b5beb3cf2c7c781277583&coordtype=" + coordtype +
34                 "&location=" +  latitude + "," + longitude + "&output=json";
35         String requestResult = SendRequest(requstUrl);
36         try {
37             retJson = (DBObject)((DBObject)JSON.parse(requestResult)).get("result");
38         } catch (Exception e) {}
39         
40         return retJson;
41     }
42     

运行结果:

 1 public static void main(String[] argv) {
 2         DBObject obj = requestRelLocacion("116.46","39.92","wgs84ll");
 3         System.out.println(obj);
 4         //打印结果如下:
 5         /*{
 6             "location": {
 7                 "lng": 116.47274785743,
 8                 "lat": 39.927001495651
 9             },
10             "formatted_address": "北京市朝阳区呼家楼西里七巷甲12号",
11             "business": "呼家楼,京广桥,团结湖",
12             "addressComponent": {
13                 "city": "北京市",
14                 "district": "朝阳区",
15                 "province": "北京市",
16                 "street": "呼家楼西里七巷",
17                 "street_number": "甲12号"
18             },
19             "cityCode": 131
20         }*/
21     }
原文地址:https://www.cnblogs.com/Wen-yu-jing/p/4077175.html