国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

通過地址定位坐標

2019-11-15 00:48:14
字體:
來源:轉載
供稿:網友
通過地址定位坐標

隨筆寫來玩玩

public class getXYByAliyunAPI {    public static void main(String[] args) {        Connection conn =null;        FileOutputStream fis =null;        try {            conn = JDBCUtil.getConnection();            PReparedStatement pstm = conn.prepareStatement("select unitCode,REPLACE(unitAddress, '#', '') from useWaterUnit");            ResultSet rs =pstm.executeQuery();            while(rs.next()){                String unitAddress = rs.getString(2);                String unitCode = rs.getString(1)+",";                String string= sendGet("http://gc.ditu.aliyun.com/geocoding", "a="+unitAddress+"&c=成都");                string = string.replace("}", "");                string = string.replace("{", "");                string = string.replace("/"", "");                string = string.replace(":", "");                String[] strings = string.split(",");                for (String s : strings) {                    s = s.trim();                    if(s.indexOf("lon")!=-1){                        unitCode+=s.substring(s.indexOf("lon") + 3, s.length())+",";                        System.out.println(unitCode+s.substring(s.indexOf("lon") + 3, s.length()));                    }                    if(s.indexOf("lat")!=-1){                        unitCode+=s.substring(s.indexOf("lat") + 3, s.length())+",/r/n";                        System.out.println(unitCode+s.substring(s.indexOf("lat") + 3, s.length()));                    }                }                fis = new FileOutputStream("d:/001.txt", true);                fis.write(unitCode.getBytes());                fis.flush();            }        } catch (SQLException e) {            e.printStackTrace();        } catch (ClassNotFoundException e) {            e.printStackTrace();        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                if(null!=conn){                    conn.close();                }                if(null!=fis){                    fis.close();                }            } catch (SQLException e) {                e.printStackTrace();            } catch (IOException e) {                e.printStackTrace();            }        }    }    public static String sendGet(String url, String param) {        String result = "";        BufferedReader in = null;        try {            String urlNameString = url + "?" + param;            URL realUrl = new URL(urlNameString);            // 打開和URL之間的連接            URLConnection connection = realUrl.openConnection();            // 設置通用的請求屬性            connection.setRequestProperty("user-agent", "directclient");            // 建立實際的連接            connection.connect();            // 獲取所有響應頭字段            Map<String, List<String>> map = connection.getHeaderFields();            // 遍歷所有的響應頭字段            for (String key : map.keySet()) {         //       System.out.println(key + "--->" + map.get(key));            }            // 定義 BufferedReader輸入流來讀取URL的響應            in = new BufferedReader(new InputStreamReader(                    connection.getInputStream()));            String line;            while ((line = in.readLine()) != null) {                result += line;            }        } catch (Exception e) {            System.out.println("發送GET請求出現異常!" + e);            e.printStackTrace();        }        // 使用finally塊來關閉輸入流        finally {            try {                if (in != null) {                    in.close();                }            } catch (Exception e2) {                e2.printStackTrace();            }        }        return result;    }}

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苏尼特左旗| 华容县| 邵阳市| 沙湾县| 汕头市| 仙居县| 哈尔滨市| 黔西| 郴州市| 屯昌县| 苗栗市| 施甸县| 五台县| 永丰县| 绥阳县| 曲靖市| 元氏县| 雅安市| 偃师市| 当阳市| 炎陵县| 临澧县| 宁波市| 棋牌| 钟山县| 旺苍县| 云南省| 苗栗县| 和平县| 林芝县| 宁国市| 桂林市| 綦江县| 台湾省| 光泽县| 仪征市| 荃湾区| 黄平县| 沛县| 孟村| 若羌县|