public static String getAddress(double latitude, double longitude){
String address = "";
String url = "http://maps.google.cn/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&sensor=true,language=zh-CN";
JSONObject obj = httpGet(url);
try {
if (obj.getString("status").equals("OK")){
JSONArray ja = JSON.parseArray(obj.getString("results"));
JSONObject jo = JSON.parseObject(ja.getString(0));
address = jo.getString("formatted_address");
}
} catch (JSONException e) {
e.printStackTrace();
}
return address;
}
得到的结果是
{
"results" : [
{
"address_components" : [
{
"long_name" : "三星河西路",
"short_name" : "三星河西路",
"types" : [ "route" ]
},
{
"long_name" : "启东市",
"short_name" : "启东市",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "南通市",
"short_name" : "南通市",
"types" : [ "locality", "political" ]
},
{
"long_name" : "江苏省",
"short_name" : "江苏省",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国江苏省南通市启东市三星河西路",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 31.80471519999999,
"lng" : 121.5974265
},
"southwest" : {
"lat" : 31.8010305,
"lng" : 121.5947618
}
},
"location" : {
"lat" : 31.8028837,
"lng" : 121.5960734
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 31.80471519999999,
"lng" : 121.5974431302915
},
"southwest" : {
"lat" : 31.8010305,
"lng" : 121.5947451697085
}
}
},
"place_id" : "ChIJp4KxuQ_9sTURgjlmYR-EVdk",
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "启东市",
"short_name" : "启东市",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "南通市",
"short_name" : "南通市",
"types" : [ "locality", "political" ]
},
{
"long_name" : "江苏省",
"short_name" : "江苏省",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国江苏省南通市启东市",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 32.1230276,
"lng" : 121.9751853
},
"southwest" : {
"lat" : 31.6170391,
"lng" : 121.4314881
}
},
"location" : {
"lat" : 31.793278,
"lng" : 121.655432
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 32.1230276,
"lng" : 121.9751853
},
"southwest" : {
"lat" : 31.6170391,
"lng" : 121.4314881
}
}
},
"place_id" : "ChIJe2KEZhUcrjURttkD8epMbU4",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"address_components" : [
{
"long_name" : "南通市",
"short_name" : "南通市",
"types" : [ "locality", "political" ]
},
{
"long_name" : "江苏省",
"short_name" : "江苏省",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国江苏省南通市",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 32.7111345,
"lng" : 121.9751853
},
"southwest" : {
"lat" : 31.6170391,
"lng" : 120.2023156
}
},
"location" : {
"lat" : 31.980171,
"lng" : 120.894291
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 32.1232631,
"lng" : 121.0250473
},
"southwest" : {
"lat" : 31.9006504,
"lng" : 120.7256162
}
}
},
"place_id" : "ChIJC-ohLkd4sTURVqJkkGIKJZY",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "江苏省",
"short_name" : "江苏省",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国江苏省",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.1245133,
"lng" : 121.9751853
},
"southwest" : {
"lat" : 30.7578404,
"lng" : 116.3619603
}
},
"location" : {
"lat" : 33.1401715,
"lng" : 119.7889248
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.124353,
"lng" : 121.962778
},
"southwest" : {
"lat" : 30.7578404,
"lng" : 116.3619603
}
}
},
"place_id" : "ChIJRcJLMdoAtzURtVOFbLbqlI0",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 53.56097399999999,
"lng" : 134.7728099
},
"southwest" : {
"lat" : 17.9996,
"lng" : 73.4994136
}
},
"location" : {
"lat" : 35.86166,
"lng" : 104.195397
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 53.56097399999999,
"lng" : 134.7726951
},
"southwest" : {
"lat" : 18.1618062,
"lng" : 73.5034261
}
}
},
"place_id" : "ChIJwULG5WSOUDERbzafNHyqHZU",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}