根据经纬度查询具体地址

根据经纬度查询地址详细信息, Java 代码实现

public static String getAdd(String lng, String lat)
    {
        String urlString = "http://api.map.baidu.com/geocoder/v2/?ak=pWNVQZQIhhhtdXhgxdBKtoMxhMFNhWPC&callback=renderReverse&location="+  lat + "," +lng;
        String res = "";
        BufferedReader in = null;
        try
        {
            URL url = new URL(urlString);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String line = null;
            while ((line = in.readLine()) != null)
            {
                    res += line + "\n";
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                in.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
        return res;
    }

 

你可能感兴趣的:(java)