1

I'm getting my position from an address, I use this website:

I get JSON data, but I dont know how to read it in my Android app.

{
  "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 ]

    }

  } ]

}

How can I read the "coordinates" tag?

Thank you in advance!

Daniele
  • 1,005
  • 9
  • 26
user1256477
  • 10,763
  • 7
  • 38
  • 62

2 Answers2

3

parse it, to begin with, then access the various elements :

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

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

and so on

njzk2
  • 38,969
  • 7
  • 69
  • 107
0

I would suggest using some sort of framwork to handle your Json data, here's a good aexample. Then you can handle your data as a regular object.

Sending and Parsing JSON Objects

Good luck!

Community
  • 1
  • 1
Magnus Karlsson
  • 3,549
  • 3
  • 31
  • 57