java高德地图坐标回显的代码
时间: 2024-06-10 13:06:22 浏览: 111
以下是一个简单的Java高德地图坐标回显的示例代码:
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class GaoDeAPI {
public static void main(String[] args) {
String url = "https://restapi.amap.com/v3/geocode/regeo?key=您的key&location=116.481488,39.990464&radius=1000&extensions=all&batch=false&roadlevel=0";
String result = sendGet(url);
System.out.println(result);
}
public static String sendGet(String url) {
String result = "";
BufferedReader in = null;
try {
URL realUrl = new URL(url);
URLConnection connection = realUrl.openConnection();
connection.connect();
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
}
```
该代码使用Java的URLConnection类与高德地图API进行交互,请求返回的结果为JSON格式的数据。您需要将代码中的“您的key”替换为您自己的高德地图开发者密钥,并将“location”参数的经纬度值替换为您想要查询的地点的经纬度。执行代码后,您将获得包括地址、邮编、城市、经纬度等信息的返回结果。
阅读全文