从谷歌歌厅JSON响应的地方API中的机器人 [英] Geting json response from Google places API in android

查看:221
本文介绍了从谷歌歌厅JSON响应的地方API中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的简单的Andr​​oid应用使用谷歌的地方API来获取一个地方的经度和纬度。我正在从谷歌API的JSON响应如下

  {
   结果:      {
         address_components:[
            {
               LONG_NAME:奈,
               SHORT_NAME:奈,
               类型:本地,政治]
            },
            {
               LONG_NAME:奈,
               SHORT_NAME:奈,
               类型:administrative_area_level_2,政治]
            },
            {
               LONG_NAME:泰米尔纳德邦
               SHORT_NAME:TN,
               类型:administrative_area_level_1,政治]
            },
            {
               LONG_NAME:印度,
               SHORT_NAME:IN,
               类型:国家,政治]
            }
         ]
         的formatted_address:金奈,印度泰米尔纳德邦
         几何体:{
            界限:{
               东北:{
                  纬度:13.23408510,
                  LNG:80.33229129999999
               },
               西南:{
                  纬度:12.94592670,
                  LNG:80.14878270
               }
            },
            位置 : {
               纬度:13.0604220,
               LNG:80.2495830
            },
            LOCATION_TYPE:近似
            视口:{
               东北:{
                  纬度:13.14736150,
                  LNG:80.37764240
               },
               西南:{
                  纬度:12.97345190,
                  LNG:80.12152360
               }
            }
         },
         类型:本地,政治]
      }
   ]
   状态:OK
}

现在我想要得到这部分的JSON响应,

 位置:{
           纬度:13.0604220,
           LNG:80.2495830
        }

我只能通过这种方法得到整个几何一部分字符串

 的JSONObject E = address.getJSONObject(0);
e.getString(几何)

如何使用的唯一位置值。任何帮助是AP preciated。我不知道是怎么回事错的。


解决方案

 的JSONObject E = address.getJSONObject(0);
JSONObject的jsonLocation = e.getJSONObject(几何)getJSONObject(位置);

和使用

 字符串纬度= jsonLocation.getString(纬度);
字符串LNG = jsonLocation.getString(LNG);

让的经度和纬度。

My simple android application uses google places api to get the latitude and longitude of a place. I am getting the json response from the google api as below

 {
   "results" : [

      {
         "address_components" : [
            {
               "long_name" : "Chennai",
               "short_name" : "Chennai",
               "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.23408510,
                  "lng" : 80.33229129999999
               },
               "southwest" : {
                  "lat" : 12.94592670,
                  "lng" : 80.14878270
               }
            },
            "location" : {
               "lat" : 13.0604220,
               "lng" : 80.2495830
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 13.14736150,
                  "lng" : 80.37764240
               },
               "southwest" : {
                  "lat" : 12.97345190,
                  "lng" : 80.12152360
               }
            }
         },
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

Now i want to get the this part in the json response,

"location" : {
           "lat" : 13.0604220,
           "lng" : 80.2495830
        }

I only get the whole "geometry" part as string through this method

JSONObject e = address.getJSONObject(0);
e.getString("geometry")

How to use the only location values. Any help is appreciated. I'm not sure what is going wrong.

解决方案

JSONObject e = address.getJSONObject(0);
JSONObject jsonLocation = e.getJSONObject("geometry").getJSONObject("location");

and use

String lat = jsonLocation.getString("lat");
String lng = jsonLocation.getString("lng");

to get latitude and longitude.

这篇关于从谷歌歌厅JSON响应的地方API中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆