在我的 android 应用程序中:我想像使用地理编码器一样提取位置、行政区域、国家名称、邮政编码、地址行,但我无法从谷歌地图 api JSON 格式中提取特定值,因为有时格式不同。
任何人有一个想法?
我的 JSON 飞行
{
"results" : [
{
"address_components" : [
{
"long_name" : "17/T116",
"short_name" : "17/T116",
"types" : []
},
{
"long_name" : "Thirunagar",
"short_name" : "Thirunagar",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Jafferkhanpet",
"short_name" : "Jafferkhanpet",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "MAS",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "600083",
"short_name" : "600083",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "17/T116, Thirunagar, Jafferkhanpet, Chennai, Tamil Nadu 600083, India",
"geometry" : {
"location" : {
"lat" : 13.028205,
"lng" : 80.20512149999999
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 13.0295539802915,
"lng" : 80.2064704802915
},
"southwest" : {
"lat" : 13.0268560197085,
"lng" : 80.20377251970849
}
}
},
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "Kalaimagal Nagar",
"short_name" : "Kalaimagal Nagar",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Ekkatuthangal",
"short_name" : "Ekkatuthangal",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "MAS",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kalaimagal Nagar, Ekkatuthangal, Chennai, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.0279001,
"lng" : 80.207994
},
"southwest" : {
"lat" : 13.0235429,
"lng" : 80.20417399999999
}
},
"location" : {
"lat" : 13.0263166,
"lng" : 80.20633549999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.0279001,
"lng" : 80.207994
},
"southwest" : {
"lat" : 13.0235429,
"lng" : 80.20417399999999
}
}
},
"types" : [ "neighborhood", "political" ]
},
{
"address_components" : [
{
"long_name" : "Ekkatuthangal",
"short_name" : "Ekkatuthangal",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "MAS",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Ekkatuthangal, Chennai, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.029174,
"lng" : 80.207994
},
"southwest" : {
"lat" : 13.013609,
"lng" : 80.18614409999999
}
},
"location" : {
"lat" : 13.020991,
"lng" : 80.19727019999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.029174,
"lng" : 80.207994
},
"southwest" : {
"lat" : 13.013609,
"lng" : 80.18614409999999
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "600083",
"short_name" : "600083",
"types" : [ "postal_code" ]
},
{
"long_name" : "Chennai",
"short_name" : "MAS",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chennai, Tamil Nadu 600083, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.046442,
"lng" : 80.21846479999999
},
"southwest" : {
"lat" : 13.0235679,
"lng" : 80.1837482
}
},
"location" : {
"lat" : 13.0368076,
"lng" : 80.20145429999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.046442,
"lng" : 80.21846479999999
},
"southwest" : {
"lat" : 13.0235679,
"lng" : 80.1837482
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chennai, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.1595488,
"lng" : 80.30683239999999
},
"southwest" : {
"lat" : 12.9666707,
"lng" : 80.1801967
}
},
"location" : {
"lat" : 13.060422,
"lng" : 80.249583
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.1595488,
"lng" : 80.30683239999999
},
"southwest" : {
"lat" : 12.9666707,
"lng" : 80.1801967
}
}
},
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Chennai",
"short_name" : "MAS",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Chennai",
"short_name" : "Chennai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Chennai, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.2339843,
"lng" : 80.3322912
},
"southwest" : {
"lat" : 12.8339608,
"lng" : 80.08155099999999
}
},
"location" : {
"lat" : 13.0524139,
"lng" : 80.25082460000002
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.2339843,
"lng" : 80.3322912
},
"southwest" : {
"lat" : 12.8339608,
"lng" : 80.08155099999999
}
}
},
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.496666,
"lng" : 80.3464511
},
"southwest" : {
"lat" : 8.077606899999999,
"lng" : 76.23055409999999
}
},
"location" : {
"lat" : 11.1271225,
"lng" : 78.6568942
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.496666,
"lng" : 80.3464511
},
"southwest" : {
"lat" : 8.077606899999999,
"lng" : 76.23055409999999
}
}
},
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.5044752,
"lng" : 97.395555
},
"southwest" : {
"lat" : 6.747138899999999,
"lng" : 68.1623859
}
},
"location" : {
"lat" : 20.593684,
"lng" : 78.96288
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.5044752,
"lng" : 97.395555
},
"southwest" : {
"lat" : 6.747138899999999,
"lng" : 68.1627956
}
}
},
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
有时像这样的Json
{
"results" : [
{
"address_components" : [
{
"long_name" : "State Highway 73A",
"short_name" : "SH 73A",
"types" : [ "route" ]
},
{
"long_name" : "Madurai",
"short_name" : "Madurai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "625706",
"short_name" : "625706",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "State Highway 73A, Tamil Nadu 625706",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 9.865866799999999,
"lng" : 77.8862288
},
"southwest" : {
"lat" : 9.8630178,
"lng" : 77.88380289999999
}
},
"location" : {
"lat" : 9.863830799999999,
"lng" : 77.88440989999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 9.865866799999999,
"lng" : 77.8863648302915
},
"southwest" : {
"lat" : 9.8630178,
"lng" : 77.88366686970849
}
}
},
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "Kalappanpatti",
"short_name" : "Kalappanpatti",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Madurai",
"short_name" : "Madurai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kalappanpatti, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 9.878088900000002,
"lng" : 77.86875909999999
},
"southwest" : {
"lat" : 9.834436999999999,
"lng" : 77.829544
}
},
"location" : {
"lat" : 9.8540633,
"lng" : 77.85387969999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 9.878088900000002,
"lng" : 77.86875909999999
},
"southwest" : {
"lat" : 9.834436999999999,
"lng" : 77.829544
}
}
},
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "625529",
"short_name" : "625529",
"types" : [ "postal_code" ]
},
{
"long_name" : "Madurai",
"short_name" : "Madurai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Tamil Nadu 625529, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 9.9536049,
"lng" : 77.9122581
},
"southwest" : {
"lat" : 9.8377929,
"lng" : 77.8131497
}
},
"location" : {
"lat" : 9.8930471,
"lng" : 77.87102849999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 9.9536049,
"lng" : 77.9122581
},
"southwest" : {
"lat" : 9.8377929,
"lng" : 77.8131497
}
}
},
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Madurai",
"short_name" : "Madurai",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Madurai, Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 10.3264033,
"lng" : 78.4698485
},
"southwest" : {
"lat" : 9.553354499999999,
"lng" : 77.4357605
}
},
"location" : {
"lat" : 9.953277900000002,
"lng" : 78.0195387
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 10.3264033,
"lng" : 78.4698485
},
"southwest" : {
"lat" : 9.553354499999999,
"lng" : 77.4357605
}
}
},
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Tamil Nadu",
"short_name" : "TN",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Tamil Nadu, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 13.496666,
"lng" : 80.3464511
},
"southwest" : {
"lat" : 8.077606899999999,
"lng" : 76.23055409999999
}
},
"location" : {
"lat" : 11.1271225,
"lng" : 78.6568942
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 13.496666,
"lng" : 80.3464511
},
"southwest" : {
"lat" : 8.077606899999999,
"lng" : 76.23055409999999
}
}
},
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.5044752,
"lng" : 97.395555
},
"southwest" : {
"lat" : 6.747138899999999,
"lng" : 68.1623859
}
},
"location" : {
"lat" : 20.593684,
"lng" : 78.96288
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.5044752,
"lng" : 97.395555
},
"southwest" : {
"lat" : 6.747138899999999,
"lng" : 68.1627956
}
}
},
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}
我试过了
JSONObject jObject = new JSONObject(s);
JSONObject results= jObject.getJSONObject("results");
JSONObject address= jObject.getJSONObject("address_components");
Map<String,String> map = new HashMap<String,String>();
Iterator iter = address.keys();
while(iter.hasNext()){
String key = (String)iter.next();
String value = menu.getString(key);
map.put(key,value);
}
它没有返回正确的值..
帮我。提前致谢