Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. Log.d("seee",makeURL());
  2.  
  3. final MarkerOptions markerOptions=new MarkerOptions();
  4. final StringRequest stringRequest = new StringRequest(Request.Method.POST, makeURL(), new Response.Listener<String>() {
  5. List<LatLng> startLatLng=null;
  6. @Override
  7. public void onResponse(String response) {
  8. JSONObject json=null;
  9.  
  10.  
  11. try {
  12.  
  13.  
  14. json = new JSONObject(response);
  15. JSONArray routeArray = json.getJSONArray("routes");
  16. for(int i=0;i<routeArray.length();i++) {
  17. JSONObject routes = routeArray.getJSONObject(i);
  18. JSONArray rAQI=routeArray.getJSONObject(i).getJSONArray("legs").getJSONObject(0).getJSONArray("steps");
  19. startLatLng=getLatitudeLongitudes(rAQI);
  20.  
  21. JSONObject overviewPolylines = routes
  22. .getJSONObject("overview_polyline");
  23. String encodedString = overviewPolylines.getString("points");
  24. List<LatLng> list = PolyUtil.decode(encodedString);
  25. if(i!=0) {
  26. PolylineOptions options = new PolylineOptions().width(17).color(ContextCompat.getColor(context,R.color.colorGreyline)).geodesic(true);
  27. for (int z = 0; z < list.size(); z++) {
  28. LatLng point = list.get(z);
  29. options.add(point);
  30. }
  31. gMap.addPolyline(options);
  32. options.clickable(true);
  33.  
  34. }
  35. else {
  36. PolylineOptions options = new PolylineOptions().width(20).color(ContextCompat.getColor(context,R.color.colorBlueline)).geodesic(true);
  37. for (int z = 0; z < list.size(); z++) {
  38. LatLng point = list.get(z);
  39. options.add(point);
  40. }
  41. gMap.addPolyline(options);
  42. options.clickable(true);
  43. }
  44. }
  45. } catch (JSONException e) {
  46. e.printStackTrace();
  47. }
  48. Toast.makeText(context, ""+startLatLng.size(), Toast.LENGTH_SHORT).show();
  49.  
  50. }
  51. }, new Response.ErrorListener() {
  52. @Override
  53. public void onErrorResponse(VolleyError error) {
  54.  
  55. Toast.makeText(context, "" + error.getMessage(), Toast.LENGTH_SHORT).show();
  56. }
  57. }) {
  58. @Override
  59. protected Map<String, String> getParams() throws AuthFailureError {
  60. Map<String, String> params = new HashMap<>();
  61. return params;
  62. }
  63. };
  64. RequestQueue queue = Volley.newRequestQueue(context);
  65. queue.add(stringRequest);
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement