-2

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setcontentview(r.layout.activity_main);

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "https://developers.zomato.com/api/v2.1/search?&lat=27&lon=153";
    JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // response
                    Log.d("Response", response.toString());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    Log.d("ERROR", "error => " + error.toString());
                }
            }
    ) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("user-key", "55a1d18014dd0c0dac534c02598a3368");
            params.put("Accept", "application/json");

            return params;
        }
    };
    queue.add(postRequest);
}

>

but i am getting all the restaurants not nearby and also please tell me how to list down the response in application.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • have you tried to look in the documentation of your api to resolve issue? – Umar Hussain Mar 05 '18 at 11:07
  • What you need to do: 1. read the API documentation (basically you need to call https://developers.zomato.com/api/v2.1/geocode), 2. Learn how to use Volley to make a call and retrieve the information. 3. Learn how to display a list of items. There are plenty of tuto all over the place. Then come back if you are really stuck. – Eselfar Mar 05 '18 at 11:07
  • also where is the code where you tried to add the result data to a list view or recycler view – Umar Hussain Mar 05 '18 at 11:08
  • sir, i am very new to android studio . i am not able to list down the responses.. please help me with the code. – Komal Gupta Mar 06 '18 at 05:18
  • restaurants = json.getJSONArray(restaurants); for(int i = 0; i < restaurants.length(); i++){ JSONObject c = restaurants.getJSONObject(i); String name = c.getString(name); String locality = c.getString(locality); String city = c.getString(city); String address = c.getString(address); sir, i tried to do this to display result. – Komal Gupta Mar 06 '18 at 06:13
  • or else u can tell me the code of just to list down near by restaurants using google api. please help me with the code.. – Komal Gupta Mar 06 '18 at 07:25

1 Answers1

0

You have to parse the JSON response in json arrays and json objects respectively ,

For learning follow this link :- How to parse JSON in Android

then you have to past the list to your list view or recycler view view adapter .

for that follow this tutorial :- https://medium.com/@peterekeneeze/parsing-remote-json-to-recyclerview-android-1ad927e96d58

hamza khan
  • 141
  • 1
  • 11