高德地图坐标转换为具体地址

java 高德地图坐标转换为具体地址

/**
* 通过经纬度查询地址 查询不出来 结果返回空字符串
*
* @param longitude 经度 大于180
* @param latitude 纬度
* @return
*/
public static String getLocation(String longitude, String latitude) {

	String location = longitude + "," + latitude;

	String str = "https://restapi.amap.com/v3/geocode/regeo?location=" + location + "&key=" + key;
	String res = getResponse(str);

	String formattedAddress = "";
	JSONObject jaon = JSONObject.parseObject(res);
	if (jaon.getInteger("status") == 1) {
		JSONObject regeocode = jaon.getJSONObject("regeocode");
		formattedAddress = regeocode.getString("formatted_address");
	}

	return formattedAddress;
}

public static String getResponse(String serverUrl) {
	
	StringBuffer result = new StringBuffer();
	try {
		URL url = new URL(serverUrl);
		URLConnection conn = url.openConnection();
		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line;
		while ((line = in.readLine()) != null) {
			result.append(line);
		}
		in.close();
	} catch (MalformedURLException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return result.toString();
}

你可能感兴趣的:(高德地图,java)