public static String getLoc(String log, String lat) {
// type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)
String urlString = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + log + "&type=010";
java.io.BufferedReader in = null;
String loc = "";
try {
URL url = new URL(urlString);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
loc += line + "\n";
}
JSONObject jsonObject = JSONObject.fromObject(loc);
JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("addrList"));
JSONObject result = JSONObject.fromObject(jsonArray.get(0));
loc = result.getString("admName");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return loc;
}