zoukankan      html  css  js  c++  java
  • 利用百度地图WEB服务APIGeoCoding API批量地址解析

      Geocoding API包括地址解析和逆地址解析功能:

      地理编码:即地址解析,由详细到街道的结构化地址得到百度经纬度信息,例如:“北京市海淀区中关村南大街27号”地址解析的结果是“lng:116.31985,lat:39.959836”。同时,地理编码也支持名胜古迹、标志性建筑名称直接解析返回百度经纬度,例如:“百度大厦”地址解析的结果是“lng:116.30815,lat:40.056885” ,通用的POI检索需求,建议使用Place API。

      逆地理编码:即逆地址解析,由百度经纬度信息得到结构化地址信息,例如:“lat:31.325152,lng:120.558957”逆地址解析的结果是“江苏省苏州市虎丘区塔园路318号”。

      本文所讲的是地理编码,从本地硬盘读取excel数据,地址解析,将结果存到本地的excel数据表当中。

      主要代码如下:

      

            try{
                address = URLEncoder.encode(address,"UTF-8");
                
                URL resjson = new URL("http://api.map.baidu.com/geocoder/v2/?address="
                        +address+"&output=json&ak="+key+"&callback=showLocation");
                BufferedReader in = null;
                if(resjson.openStream()!=null){
                    in = new BufferedReader(new InputStreamReader(resjson.openStream()));
                }
                
                String res;
                StringBuilder sb = new StringBuilder("");
                while ((res=in.readLine())!=null) {
                    
                    sb.append(res.trim());
                }
                
                in.close();
                String str = sb.toString();
                //System.out.println("return json:"+str);
                
                Map<String,String> map = null;
                if(str!=null)
                {
                    int lngStart = str.indexOf("lng\":");
                    int lngEnd = str.indexOf(",\"lat");
                    int latEnd = str.indexOf("},\"precise");
                    int preciseEnd = str.indexOf(",\"confidence");
                    int confidenceEnd = str.indexOf(",\"level");
                    if(lngStart>0&&lngEnd>0&&latEnd>0){
                        String lng = str.substring(lngStart+5,lngEnd);
                        String lat = str.substring(lngEnd+7,latEnd);
                        String precise = str.substring(latEnd+12,preciseEnd);
                        String confidence = str.substring(preciseEnd+14,confidenceEnd);
                        map = new HashMap<String, String>();
                        map.put("lng", lng);
                        map.put("lat", lat);
                        map.put("precise", precise);
                        map.put("confidence", confidence);
                        return map;
                        
                    }
                    
                }
                }catch(Exception e){
                    e.printStackTrace();
                }
                
                return null;
            }

        取得的结果数据主要包括了对应地址的经度、纬度、是否精确查找,打点的可信度。

      

  • 相关阅读:
    Python操作Word:常用对象介绍
    Python入门教程 超详细1小时学会Python
    用几何画板画七边形的方法
    用ChemDraw画3D图的方法
    Chem 3D模型的参数值更改方法
    Chem 3D中怎么创建立体模型
    在几何画板中输入绝对值的方法
    怎么给几何画板文字加立体阴影效果
    几何画板放大和缩小的方法
    ChemDraw Pro和ChemBio3D Ultra有什么区别
  • 原文地址:https://www.cnblogs.com/cnugis/p/5374409.html
Copyright © 2011-2022 走看看