Domanda

Sto scrivendo una richiesta httpget per Android che interroga l'API Foursquare per l'evento nelle vicinanze. La risposta in JSON che ricevo indietro è

{"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
    },

Ci possono essere molti di questi luoghi. Posso farlo per stampare le informazioni locali utilizzando questo codice

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();

Come posso accedere ai valori geolat & geolong?

È stato utile?

Soluzione

Credo che mettendo questo codice dentro il ciclo for dovrebbe fare il trucco:

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

Altri suggerimenti

È possibile controllare qui e scegliere una libreria JSON da utilizzare per arrivare a quelli valori.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top