从谷歌地图获取JSON的坐标

时间:2012-03-09 16:04:18

标签: android json

我从地址获取职位,我使用website

我获得了JSON数据,但我不知道如何在我的Android应用中阅读它。

{
  "name": "plaza mayor 1 madrid España",

  "Status": {

    "code": 200,

    "request": "geocode"

  },

  "Placemark": [ {

    "id": "p1",

    "address": "Plaza Mayor, 1, 28012 Madrid, España",

    "AddressDetails": {

   "Accuracy" : 8,

   "Country" : {

      "AdministrativeArea" : {

         "AdministrativeAreaName" : "Comunidad de Madrid",

         "SubAdministrativeArea" : {

            "Locality" : {

               "LocalityName" : "Madrid",

               "PostalCode" : {

                  "PostalCodeNumber" : "28012"

               },

               "Thoroughfare" : {

                  "ThoroughfareName" : "Plaza Mayor, 1"

               }

            },

            "SubAdministrativeAreaName" : "Madrid"

         }

      },

      "CountryName" : "España",

      "CountryNameCode" : "ES"

   }

},

    "ExtendedData": {

      "LatLonBox": {

        "north": 40.4164186,

        "south": 40.4137207,

        "east": -3.7053139,

        "west": -3.7080118

      }

    },

    "Point": {

      "coordinates": [ -3.7066379, 40.4150359, 0 ]

    }

  } ]

}

如何阅读“coordinates”标签?

提前谢谢!

2 个答案:

答案 0 :(得分:3)

解析它,然后开始,然后访问各种元素:

JSONObject response = new JSONObject(responseAsString);
JSONObject point = response.getJSONArray("Placemark").getJSONObject(0).getJSONObject("Point");

double lat = point.getJSONArray("coordinates").getDouble(0);

等等

答案 1 :(得分:0)

我建议使用某种框架来处理你的Json数据,这是一个很好的例子。然后,您可以将数据作为常规对象处理。

Sending and Parsing JSON Objects

祝你好运!