日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

通过地址定位坐标

發布時間:2025/3/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过地址定位坐标 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

隨筆寫來玩玩

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;} }

?

  

轉載于:https://www.cnblogs.com/learningchencheng/p/4630718.html

總結

以上是生活随笔為你收集整理的通过地址定位坐标的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。