高德开放平台入口
AddressUntils
import com.alibaba.fastjson.JSONObject;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLConnection;public class AddressUntils {//这里添加应用的时候记得要使用windows平台的不要获取小程序或其他的否则会报错private static final String key = "e6915e035df85c0c56d385800axxxxxx";//key值我用的是高德的keypublic static void main(String[] args) {String add = getAdd("116.3039", "39.97646");JSONObject jsonObject = JSONObject.parseObject(add);JSONObject json = jsonObject.getJSONObject("regeocode");String address = json.getString("formatted_address");String infocode = jsonObject.getString("infocode");System.out.println(address);System.out.println(add);}public static String getAdd(String lng, String lat){String urlString = "/v3/geocode/regeo?key="+key+"&location="+lng+ "," +lat;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;}}