Guest User

Untitled

a guest
Nov 13th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. public void GetChildLocation(){
  2. StringRequest stringRequest = new StringRequest(Request.Method.POST, LAST_COORDINATE_URL, new Response.Listener<String>() {
  3. @Override
  4. public void onResponse(String response) {
  5. try {
  6. JSONObject jsonObject = new JSONObject(response);
  7. JSONArray jsonArray = jsonObject.getJSONArray("data");
  8.  
  9. JSONObject location = jsonArray.getJSONObject(0);
  10.  
  11. LatLng newLatLng = new LatLng(Double.parseDouble(location.getString("latitude")),Double.parseDouble(location.getString("longitude")));
  12. if (latlng != null) {
  13. double PI = 3.14159;
  14. //Source
  15. double lat1 = latlng.latitude* PI / 180;
  16. double lng1 = latlng.longitude* PI / 180;
  17. // destination
  18. double lat2 = newLatLng.latitude* PI / 180;
  19. double lng2 = newLatLng.longitude* PI / 180;
  20. double dLon = (lng2 - lng1);
  21. double y = Math.sin(dLon) * Math.cos(lat2);
  22. double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
  23. double brng = Math.toDegrees((Math.atan2(y, x)));
  24. brng = (brng + 360) % 360;
  25.  
  26. mMap.animateCamera(CameraUpdateFactory.newLatLng(newLatLng));
  27. animateMarker(mCurrentLocationMarker, newLatLng, (float) brng, false);
  28. latlng = newLatLng;
  29. }
  30.  
  31. } catch (JSONException e) {
  32. e.printStackTrace();
  33. }
  34.  
  35. new Handler().postDelayed(new Runnable() {
  36. @Override
  37. public void run() {
  38. GetChildLocation();
  39. }
  40. },1000);
  41. }
  42. }, new Response.ErrorListener() {
  43. @Override
  44. public void onErrorResponse(VolleyError error) {
  45.  
  46. }
  47. }){
  48. @Override
  49. protected Map<String, String> getParams() throws AuthFailureError {
  50. Map<String,String> params = new HashMap<>();
  51. params.put("track_id",trackId);
  52. return params;
  53. }
  54. @Override
  55. public Map<String, String> getHeaders() throws AuthFailureError {
  56. Map<String,String> headers = super.getHeaders();
  57. if (headers == null || headers.equals(Collections.<String, String>emptyMap())){
  58. headers = new HashMap<String, String>();
  59. }
  60. MyApp.get().addSessionCookie(headers);
  61. return headers;
  62. }
  63. };
  64. if (getContext() != null) {
  65. try {
  66. RequestQueue queue = Volley.newRequestQueue(getContext());
  67. queue.add(stringRequest);
  68. }catch (OutOfMemoryError e){
  69. e.printStackTrace();
  70. RequestQueue queue1 = Volley.newRequestQueue(getContext());
  71. queue1.add(stringRequest);
  72. }
  73. }
  74. }
  75.  
  76. E/AndroidRuntime: FATAL EXCEPTION: main
  77. Process: digimkey.example.digimkey_4.dmk_parent_app, PID: 21684
  78. java.lang.OutOfMemoryError: Could not allocate JNI Env
  79. at java.lang.Thread.nativeCreate(Native Method)
  80. at java.lang.Thread.start(Thread.java:730)
  81. at com.android.volley.RequestQueue.start(RequestQueue.java:128)
  82. at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:91)
  83. at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:67)
  84. at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:102)
  85. at digimkey.example.digimkey_4.dmk_parent_app.TrackMap.GetChildLocation(TrackMap.java:571)
  86. at digimkey.example.digimkey_4.dmk_parent_app.TrackMap$4$1.run(TrackMap.java:539)
  87. at android.os.Handler.handleCallback(Handler.java:751)
  88. at android.os.Handler.dispatchMessage(Handler.java:95)
  89. at android.os.Looper.loop(Looper.java:154)
  90. at android.app.ActivityThread.main(ActivityThread.java:6077)
  91. at java.lang.reflect.Method.invoke(Native Method)
  92. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
  93. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Add Comment
Please, Sign In to add comment