String lng = "121.506377"; // 经度
String lat = "31.245105"; // 纬度
try {
//URL url = new URL(" https://restapi.amap.com/v3/assistant/coordinate/convert?key=a910275072f1f2ad767b56fc9d0a0a56&locations="+lng+","+lat+"&coordsys=baidu");
URL url = new URL("https://restapi.amap.com/v3/assistant/coordinate/convert?locations=116.481499,39.990475&coordsys=baidu&output=json&key=a910275072f1f2ad767b56fc9d0a0a56 ");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
out.flush();
out.close();
String sCurrentLine = "";
String sTotalString = "";
InputStream l_urlStream;
l_urlStream = connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
while ((sCurrentLine = l_reader.readLine()) != null) {
if (!sCurrentLine.equals(""))
sTotalString += sCurrentLine;
}
System.out.println(sTotalString);
} catch (Exception e) {
e.printStackTrace();
}
}
显示
{"status":"0","info":"MISSING_REQUIRED_PARAMS","infocode":"20001"}
但是我参数都 配上了 并且链接在浏览器中直接打开是成功的
{"status":"1","info":"ok","infocode":"10000","locations":"116.4748955248,39.984717169345"}