Question
Help with parsing through JSON object: here is the json object, I need to get the value of lat and long and store it into
Help with parsing through JSON object:
here is the json object, I need to get the value of lat and long and store it into
String latLong = lat + "," +long;
here is my code, what am i doing wrong?:
private static String parseGeocodeResponse(String response)
{
// TODO 4: Convert response string to JSON & dive down into JSON response to get lat/long
//convert string to JSONObject
JSONObject objResponse = new JSONObject(response);
//Get results array
JSONArray arrResults = objResponse.getJSONArray("results");
for (int r = 0; r
JSONObject objResult = arrResults.getJSONObject(r);
//looks through json object to get name and vicinity/address
//get name and address
String addressLat = objResult.getString("lat");
String addressLong = objResult.getString("long");
String latLong = addressLat + "," + addressLong;
}
return latLong;
}
- results: + address_components: [ formatted address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", - geometry: 1 + bounds: ...), location: \ lat: 38.8976633, lng:77.0365739 location type: "ROOFTOP", + viewport: [... 1, place_id: "ChIJGVtI4by3t4kRr51d Qm_x58", types: [.] 1, status: "OK" - results: + address_components: [ formatted address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", - geometry: 1 + bounds: ...), location: \ lat: 38.8976633, lng:77.0365739 location type: "ROOFTOP", + viewport: [... 1, place_id: "ChIJGVtI4by3t4kRr51d Qm_x58", types: [.] 1, status: "OKStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started