java根據經緯度擷取地址

來源:互聯網
上載者:User

標籤:etl   on()   main   puts   參數   cep   lin   exce   return   

public class GetLocation {      public static void main(String[] args) {          // lat 39.97646               //log 116.3039           String add = getAdd("116.3039", "39.97646");          JSONObject jsonObject = JSONObject.fromObject(add);          JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("addrList"));          JSONObject j_2 = JSONObject.fromObject(jsonArray.get(0));          String allAdd = j_2.getString("admName");          String arr[] = allAdd.split(",");          System.out.println("省:"+arr[0]+"\n市:"+arr[1]+"\n區:"+arr[2]);      }            public static String getAdd(String log, String lat ){          //lat 小  log  大          //參數解釋: 緯度,經度 type 001 (100代表道路,010代表POI,001代表門址,111可以同時顯示前三項)          String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010";          String res = "";             try {                 URL url = new URL(urlString);                java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();                conn.setDoOutput(true);                conn.setRequestMethod("POST");                java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(),"UTF-8"));                String line;               while ((line = in.readLine()) != null) {                   res += line+"\n";             }                in.close();            } catch (Exception e) {                System.out.println("error in wapaction,and e is " + e.getMessage());            }           System.out.println(res);          return res;        }        }  

 

java根據經緯度擷取地址

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.