Completely new to android and JSON usage. I tried to follow a few previous posts and answers but cannot get it to work. My result is of this form :
{
"searchResults": [
{
"resultNumber": 1,
"distance": 1.4849,
"sourceName": "mqap.internationalpois",
"name": "Le Restaurant",
"shapePoints": [
-37.840523,
144.991425
],
"distanceUnit": "m",
"key": "97d091ae-1a7e-48c0-b1ab-ea3a26b2da6c",
"fields": {
"cats_ext": "(all) Restaurants::French",
"phone": "+(33)-(4)-68356262",
"side_of_street": "N",
"navsics": "581208",
"lng": 144.991425,
"city": "Perpignan",
"country": "FR",
"cats": "(all) Restaurants",
"id": "12500223531687",
"mqap_geography": {
"latLng": {
"lng": 144.991425,
"lat": -37.840523
}
},
"navsics_ext": "581208::58120849",
"address": "16 Cours Lazare Escarguel",
"postal_code": "66000",
"name": "Le Restaurant",
"mqap_id": "97d091ae-1a7e-48c0-b1ab-ea3a26b2da6c",
"disp_lat": -37.840523,
"street_link_id": "",
"lat": -37.840523,
"disp_lng": 144.991425
}
},
{
"resultNumber": 2,
"distance": 11.4161,
"sourceName": "mqap.internationalpois",
"name": "Le Val d'Or",
"shapePoints": [
-37.881779,
145.167267
],
"distanceUnit": "m",
"key": "acf9c655-571e-4129-b70f-2e71f64894c2",
"fields": {
"cats_ext": "(all) Restaurants::French",
"phone": "+(33)-(3)-85451370",
"side_of_street": "N",
"navsics": "581208",
"lng": 145.167267,
"city": "Mercurey",
"country": "FR",
"cats": "(all) Restaurants",
"id": "12500223506348",
"mqap_geography": {
"latLng": {
"lng": 145.167267,
"lat": -37.881779
}
},
"navsics_ext": "581208::58120849",
"address": "140 Grande Rue",
"postal_code": "71640",
"name": "Le Val d'Or",
"mqap_id": "acf9c655-571e-4129-b70f-2e71f64894c2",
"disp_lat": -37.881779,
"street_link_id": "",
"lat": -37.881779,
"disp_lng": 145.167267
}
},
{
"resultNumber": 3,
"distance": 14.9848,
"sourceName": "mqap.internationalpois",
"name": "Le Saint Germain",
"shapePoints": [
-37.967893,
145.179022
],
"distanceUnit": "m",
"key": "66ad361d-e4c2-4e61-bfc3-dda863d84418",
"fields": {
"cats_ext": "(all) Restaurants",
"phone": "+(33)-(4)-67097575",
"side_of_street": "N",
"navsics": "581208",
"lng": 145.179022,
"city": "Pézenas",
"country": "FR",
"cats": "(all) Restaurants",
"id": "12500223648887",
"mqap_geography": {
"latLng": {
"lng": 145.179022,
"lat": -37.967893
}
},
"navsics_ext": "581208",
"address": "6 Avenue Paul Vidal de La Blache",
"postal_code": "34120",
"name": "Le Saint Germain",
"mqap_id": "66ad361d-e4c2-4e61-bfc3-dda863d84418",
"disp_lat": -37.967893,
"street_link_id": "",
"lat": -37.967893,
"disp_lng": 145.179022
}
}
],
"origin": {
"latLng": {
"lng": 144.970242,
"lat": -37.827057
},
"postalCode": "",
"adminArea5Type": "City",
"adminArea4": "",
"adminArea5": "",
"adminArea4Type": "County",
"street": "",
"adminArea1Type": "Country",
"adminArea1": "",
"adminArea3": "",
"adminArea3Type": "State"
},
"resultsCount": 3,
"hostedData": [
{
"tableName": "mqap.internationalpois",
"extraCriteria": "navsics='581208'",
"parameters": [
"581208"
],
"columnNames": []
}
],
"totalPages": 1,
"info": {
"statusCode": 0,
"copyright": {
"text": "© 2015 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2015 MapQuest, Inc."
},
"messages": []
},
"options": {
"kmlStyleUrl": "http://www.search.mapquestapi.com/kml-default.kml",
"shapeFormat": "raw",
"ambiguities": true,
"pageSize": 3,
"radius": 25,
"currentPage": 1,
"units": "m",
"maxMatches": 30
}
}
I am trying to get the lat and longitude to show them on a map. I tried creating JSON Objects like this to get the first position :
JSONObject mainObject = new JSONObject(resmsg);
JSONObject searchResults = mainObject.getJSONObject("searchResults");
JSONObject mqap_geography = searchResults.getJSONObject("mqap_geography");
JSONObject latLng = mqap_geography.getJSONObject("latLng");
Double lat = Double.parseDouble(latLng.getJSONObject("lat").toString());
Double lon = Double.parseDouble(latLng.getJSONObject("lng").toString());
Any help..