package com.baidumap;
import net.sf.json.JSONObject;
public class LngAndLatUtil {
public static String getCity(String lat, String lng) {
JSONObject obj = getLocationInfo(lat, lng).getJSONObject("result").getJSONObject("addressComponent");
return obj.getString("city");
}
public static JSONObject getLocationInfo(String lat, String lng) {
String url = "http://api.map.baidu.com/geocoder/v2/?location=" + lat + ","
+ lng + "&output=json&ak=你的ak&pois=0";
JSONObject obj = JSONObject.fromObject(HttpUtil.getRequest(url));
return obj;
}
public static void main(String[] args) {
System.out.println(LngAndLatUtil.getLocationInfo("30.00", "114"));
}
}
import net.sf.json.JSONObject;
public class LngAndLatUtil {
public static String getCity(String lat, String lng) {
JSONObject obj = getLocationInfo(lat, lng).getJSONObject("result").getJSONObject("addressComponent");
return obj.getString("city");
}
public static JSONObject getLocationInfo(String lat, String lng) {
String url = "http://api.map.baidu.com/geocoder/v2/?location=" + lat + ","
+ lng + "&output=json&ak=你的ak&pois=0";
JSONObject obj = JSONObject.fromObject(HttpUtil.getRequest(url));
return obj;
}
public static void main(String[] args) {
System.out.println(LngAndLatUtil.getLocationInfo("30.00", "114"));
}
}