zoukankan      html  css  js  c++  java
  • JAVA------20.经纬度转换省市区

    package  com.dapail.util;
    
    import java.net.URL;
    
    import net.sf.json.*;
    
    
    
    
    public class GetLocation {
        public static void main(String[] args) {  
            // lat 39.97646       
            //log 116.3039   
            String add = getAdd("116.3039", "39.97646");  
           
        }  
          
        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+"
    ";    
             }    
                in.close();    
            } catch (Exception e) {    
                System.out.println("error in wapaction,and e is " + e.getMessage());    
            }   
            System.out.println(res);  
            
            JSONObject jsonObject = JSONObject.fromObject(res);  
            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]+"
    市:"+arr[1]+"
    区:"+arr[2]);  
            
            return allAdd;    
        }  
    }
  • 相关阅读:
    Vue框架构造
    JavaScript-改变this指向
    前端发展史
    python篇第10天【For 循环语句】
    python篇第10天【While 循环语句】
    python篇第8天【运算符】
    python篇第6天【数据类型】
    python篇第5天【变量】
    Python篇函数总结【输出函数】
    python篇第3天【编码规范】
  • 原文地址:https://www.cnblogs.com/coriander/p/6961283.html
Copyright © 2011-2022 走看看