It was going good until I needed to parse the type of the place, the file is organized like this:
"geometry" : {
"location" : {
"lat" : 45.7849210,
"lng" : 11.8724490
},
"viewport" : {
"northeast" : {
"lat" : 45.81619110,
"lng" : 11.89575470
},
"southwest" : {
"lat" : 45.75432980,
"lng" : 11.84532520
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "a454072e2ba71d4e2331e39099261f086cd11d1e",
"name" : "Fonte",
"reference" : "CnRtAAAAUaGSsbXRv05lApqXueEKjOAjtkpEDz07ioe3vPS9HqpOIJSTTQWYObc6o6GfEq-pzVUtKT03oRWNx6ld-rUfdat47e8W3NbSsLY1NldO9iQEUjQOM9kIIOix8xLAvqh5YHUNTAela4Mo8HGSJPPBhhIQ9j4Uy_WrQtFO7qxirA0UHRoUsmY0ngstG5BBiHQNLkLgxTpsDEY",
"types" : [ "locality", "political" ],
"vicinity" : "Fonte"
},
As it is possible to notice that types is an string array I tried this approach:
JSONArray results = o.getJSONArray("results");
JSONObject tempObject = results.getJSONObject(0);
JSONArray typee = tempObject.getJSONArray("types");
String a = typee.getJSONObject(0).toString();
but it doesn’t work.Any help will be appreciated.The whole JSON can be seen here: https://maps.googleapis.com/maps/api/place/search/json?location=45.7909,11.8700&radius=500&key=AIzaSyC9Ob9_u-2mxCHeItDHytDLmZP-P1QCejw&sensor=true.
The above will return
localityto variableaandpoliticalto variableb. Usetypee.length()to find out how many elements are in theJSONArrayif it’s possible thattypesmight have a variable number of elements.