-
Google Map showing only one marker
about 9 years ago
-
about 9 years ago
Seems there is problem at parsing only first object is getting fetched from json array you are receiving so please use the following method for the parsing
public void requestJSONArray(final RequestCallback callback) { JsonArrayRequest req = new JsonArrayRequest(map_url, new Response.Listener
() { @Override public void onResponse(JSONArray response) { Log.d(TAG, response.toString()); // Parsing json array response // loop through each json object List json_reponse = new ArrayList<>(); json_reponse.clear(); for (int i = 0; i < response.length(); i++) { try { JSONObject json_object = (JSONObject) response .get(i); String treeid = json_object.getString("treeid"); String treespecies = json_object.getString("treespecies"); String treelatitude = json_object.getString("treelatitude"); String treelongitude = json_object.getString("treelongitude"); json_reponse.add(new MapModal(treeid,treespecies, treelatitude, treelongitude)); }catch (Exception e){e.printStackTrace();} } Log.d(TAG, ""+json_reponse.size()); // txtResponse.setText(jsonResponse); // hidepDialog(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); // Toast.makeText(getApplicationContext(), // error.getMessage(), Toast.LENGTH_SHORT).show(); // hidepDialog(); } }); // Adding request to request queue AppInitializer.getContext().getVolleyRequestQueu().add(req); } and the modal class for the same is
** * Created by amitrai on 26/10/15. */
public class MapModal { public MapModal(String treeid,String treespecies, String treelatitude,String treelongitude){ this.treeid = treeid; this.treespecies = treespecies; this.treelatitude = treelatitude; this.treelongitude =treelongitude; } public String treeid,treespecies, treelatitude,treelongitude; public String getTreeid() { return treeid; } public void setTreeid(String treeid) { this.treeid = treeid; } public String getTreespecies() { return treespecies; } public void setTreespecies(String treespecies) { this.treespecies = treespecies; } public String getTreelatitude() { return treelatitude; } public void setTreelatitude(String treelatitude) { this.treelatitude = treelatitude; } public String getTreelongitude() { return treelongitude; } public void setTreelongitude(String treelongitude) { this.treelongitude = treelongitude; } }
I have tested it all the objects are getting stored in list now just create a for loop till the size of list and do whatever you want with all the data fetched from json array.
If answers is helpful please mark the answer correct ! Happy coding :)
-
about 9 years ago
hello bharat,
please accept the answer if you find it solved your problem this will help other users to get proper answer to their quires.
-
-
about 9 years ago
Thanks Amit. I appreciate your time you took to help me!
-
3 Answer(s)