How to get latitude and longitude from JSON using volley?

Home / Uncategorized / How to get latitude and longitude from JSON using volley?

I am trying to use volley library to get longitude and latitude of a particular address. Though I have been able to get the address successfully, but I am not getting the latitude and longitude values.
String googleMapUrl = ""+ place + "&sensor=false";

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, googleMapUrl, null, new Response.Listener() {
public void onResponse(JSONObject response) {
try {
Toast.makeText(MainActivity.this, "Response "+ response, Toast.LENGTH_SHORT).show();
// JSONArray res = o.getJSONArray("results");
for (int i = 0; i < response.length(); i++) { //JSONObject jsonObj = new JSONObject(result.toString()); //JSONArray resultJsonArray = jsonObj.getJSONArray("results"); JSONObject jsonObj = (JSONObject) response.get("i"); JSONObject resultJsonArray = jsonObj.getJSONObject("results"); // Extract the Place descriptions from the results // resultList = new ArrayList(resultJsonArray.length());

JSONObject before_geometry_jsonObj = resultJsonArray.getJSONObject("0");

JSONObject geometry_jsonObj = before_geometry_jsonObj

JSONObject location_jsonObj = geometry_jsonObj

String lat_helper = location_jsonObj.getString("lat");
lat = Double.valueOf(lat_helper);

String lng_helper = location_jsonObj.getString("lng");
lng = Double.valueOf(lng_helper);

How do I go about this?


Read more

Leave a Reply

Your email address will not be published. Required fields are marked *