Pregunta

Estoy escribiendo una solicitud HTTPGet para android que consulta la API de Foursquare para el evento cercano. El responce JSON recibo de vuelta es

{"groups": [
{
  "type": "Nearby",
  "venues": [
    {
      "id": 2587838,
      "name": "Marriott Druids Glen Hotel Newtownmountkennedy",
      "primarycategory": {
        "id": 79281,
        "fullpathname": "Travel:Resort",
        "nodename": "Resort",
        "iconurl": "http://foursquare.com/img/categories/travel/resort.png"
      },
      "address": "Newtownmountkennedy",
      "city": "Newtownmountkennedy",
      "state": "",
      "verified": false,
      "geolat": 53.091717,
      "geolong": -6.079162,
      "stats": {
        "herenow": "0"
      },
      "distance": 5596
    },

Puede haber muchos de estos lugares. Puedo conseguir que se imprima la información de los lugares utilizando el código

InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
Log.i("Hoosheer0",result);

// A Simple JSONObject Creation
JSONObject json=new JSONObject(result);
JSONArray venues = json.getJSONArray("groups");
//JSONArray docsArray = jObject.getJSONArray("docs");
for (int i = 0; i<venues.length();i++){
    String name = venues.getJSONObject(i).optString("venues");
    //String venueName = name.
    Log.i("This is a name... pleasse", name);
}

instream.close();

¿Cómo puedo acceder a los valores de geolat y geolong?

¿Fue útil?

Solución

Creo al colocar el código dentro de su ciclo for debe hacer el truco:

JSONObject venueObject = venues.getJSONObject(i);
double geoLat = venueObject.getDouble("geolat");
double geoLong = venueObject.getDouble("geolong");

Otros consejos

Puede comprobar aquí y recoger una biblioteca JSON a utilizar para llegar a los valores.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top