Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void GetChildLocation(){
- StringRequest stringRequest = new StringRequest(Request.Method.POST, LAST_COORDINATE_URL, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- try {
- JSONObject jsonObject = new JSONObject(response);
- JSONArray jsonArray = jsonObject.getJSONArray("data");
- JSONObject location = jsonArray.getJSONObject(0);
- LatLng newLatLng = new LatLng(Double.parseDouble(location.getString("latitude")),Double.parseDouble(location.getString("longitude")));
- if (latlng != null) {
- double PI = 3.14159;
- //Source
- double lat1 = latlng.latitude* PI / 180;
- double lng1 = latlng.longitude* PI / 180;
- // destination
- double lat2 = newLatLng.latitude* PI / 180;
- double lng2 = newLatLng.longitude* PI / 180;
- double dLon = (lng2 - lng1);
- double y = Math.sin(dLon) * Math.cos(lat2);
- double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
- double brng = Math.toDegrees((Math.atan2(y, x)));
- brng = (brng + 360) % 360;
- mMap.animateCamera(CameraUpdateFactory.newLatLng(newLatLng));
- animateMarker(mCurrentLocationMarker, newLatLng, (float) brng, false);
- latlng = newLatLng;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- GetChildLocation();
- }
- },1000);
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- }
- }){
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- Map<String,String> params = new HashMap<>();
- params.put("track_id",trackId);
- return params;
- }
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- Map<String,String> headers = super.getHeaders();
- if (headers == null || headers.equals(Collections.<String, String>emptyMap())){
- headers = new HashMap<String, String>();
- }
- MyApp.get().addSessionCookie(headers);
- return headers;
- }
- };
- if (getContext() != null) {
- try {
- RequestQueue queue = Volley.newRequestQueue(getContext());
- queue.add(stringRequest);
- }catch (OutOfMemoryError e){
- e.printStackTrace();
- RequestQueue queue1 = Volley.newRequestQueue(getContext());
- queue1.add(stringRequest);
- }
- }
- }
- E/AndroidRuntime: FATAL EXCEPTION: main
- Process: digimkey.example.digimkey_4.dmk_parent_app, PID: 21684
- java.lang.OutOfMemoryError: Could not allocate JNI Env
- at java.lang.Thread.nativeCreate(Native Method)
- at java.lang.Thread.start(Thread.java:730)
- at com.android.volley.RequestQueue.start(RequestQueue.java:128)
- at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:91)
- at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:67)
- at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:102)
- at digimkey.example.digimkey_4.dmk_parent_app.TrackMap.GetChildLocation(TrackMap.java:571)
- at digimkey.example.digimkey_4.dmk_parent_app.TrackMap$4$1.run(TrackMap.java:539)
- at android.os.Handler.handleCallback(Handler.java:751)
- at android.os.Handler.dispatchMessage(Handler.java:95)
- at android.os.Looper.loop(Looper.java:154)
- at android.app.ActivityThread.main(ActivityThread.java:6077)
- at java.lang.reflect.Method.invoke(Native Method)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Add Comment
Please, Sign In to add comment