来自数据库的Android Volley请求太慢了

时间:2016-09-13 18:28:32

标签: android android-volley

我试图从数据库中使用排球从我的地图应用程序接收坐标,我希望它实时发生,所以我可以看到位置说可能是一辆车在移动。我的RetryPolicy有什么问题

private void sendPOST() throws IOException, JSONException {
        JSONObject obj = new JSONObject();
        obj.put("uuid", uuid);
        RequestQueue queue = Volley.newRequestQueue(context);
        JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, strUrl, obj,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        try {
                            Log.d(response.toString(), response.toString());
                            if (Integer.parseInt(response.getString("response")) == 0) {
                                JSONArray array = response.getJSONArray("coordinates");
                                for (int i = 0; i < array.length(); i++) {
                                    JSONObject object = array.getJSONObject(i);
                                    double latituder = Double.parseDouble(object.getString("latitude"));
                                    double longituder = Double.parseDouble(object.getString("longitude"));
                                    LatLng Africa = new LatLng(latituder, longituder);
                                    mGoogleMap.addMarker(new MarkerOptions()
                                            .position(Africa)
                                            .draggable(true)
                                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));

                                }

                            } else {

                                Thread.currentThread().interrupt();
                            }
                        } catch (Exception e) {
                            Log.d("receive error ;;;;;", e.toString());
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d("receive error", error.toString());
                    }
                });
        jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(0,
                -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(jsObjRequest);
    }

    public void run() {
        try {
            sendPOST();
        } catch (Exception e) {
            Log.d(e.toString(), "receive error");
        }

    }
}

0 个答案:

没有答案