Baidu API in the global reverse geocoding service will provide coordinate points (latitude and longitude) is converted to the corresponding location information (where administrative divisions surrounding the punctuation distribution) function.
URL access are:
http://api.map.baidu.com/reverse_geocoding/v3/?ak= you the Output = json & & AK started coordtype = wgs84ll
& LOCATION = latitude, longitude // GET request
Because the use of Baidu Maps API will have to apply AK, apply the following link
//JSON转化为MAP函数中需要
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
//通过经纬度获得城市信息中需要
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.11</version>
</dependency>
Cities get specific information by latitude and longitude
public static Map<String,Object> getcitydetailbyjingwei(double jing ,double wei)
{
Map<String, Object> map = null;
String url = "http://api.map.baidu.com/reverse_geocoding/v3/?"
+ "ak=你的AK&output=json&coordtype=wgs84ll&location="
+wei+","+jing;
try {
HttpClient client = HttpClientBuilder.create().build();//构建一个Client
HttpGet get = new HttpGet(url.toString()); //构建一个GET请求
HttpResponse response = client.execute(get);//提交GET请求
HttpEntity result = response.getEntity();//拿到返回的HttpResponse的"实体"
String content = EntityUtils.toString(result);
JSONObject res = JSONObject.fromObject(content);
map = JsonUtil.parseJSON2Map(res); //通过下面的函数将json转化为map
} catch (Exception e) {
e.printStackTrace();
System.out.println("获取地址失败");
}
return map;
}
By the following method into a JSON Map
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.util.*;
public class JsonUtil {
public static Map<String, Object> parseJSON2Map(JSONObject json) {
Map<String, Object> map = new HashMap<String, Object>();
// 最外层解析
for (Object k : json.keySet()) {
Object v = json.get(k);
// 如果内层还是数组的话,继续解析
if (v instanceof JSONArray) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
@SuppressWarnings("unchecked")
Iterator<JSONObject> it = ((JSONArray) v).iterator();
while (it.hasNext()) {
JSONObject json2 = it.next();
list.add(parseJSON2Map(json2));
}
map.put(k.toString(), list);
} else {
map.put(k.toString(), v);
}
}
return map;
}
}
Enter the longitude and latitude: 36.55001 118.46566
The results obtained