Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 阅读谷歌地图Json_Android - Fatal编程技术网

Android 阅读谷歌地图Json

Android 阅读谷歌地图Json,android,Android,我在阅读时间和距离方面有困难,请帮忙。到目前为止,这就是我设法到达的地方 String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-1.3070491136606004,36.824679896235466&destinations=-1.3074272067017922,36.82789519429207"; RequestQueue mRequestQueue

我在阅读时间和距离方面有困难,请帮忙。到目前为止,这就是我设法到达的地方

    String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-1.3070491136606004,36.824679896235466&destinations=-1.3074272067017922,36.82789519429207";
        RequestQueue mRequestQueue;
        Cache cache = new DiskBasedCache(getActivity().getCacheDir(), 1024 * 1024); // 1MB cap
        final Network network = new BasicNetwork(new HurlStack());
        mRequestQueue = new RequestQueue(cache, network);
        mRequestQueue.start();
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        System.out.println("Response" + response);
                        JSONObject jsonObject;
                        JSONArray jsonarray;
                        try {

                            jsonObject = new JSONObject(response);
                            jsonarray  = jsonObject.getJSONArray("rows");

                            for (int i=0; i<jsonarray.length(); i++)
                            {
                                JSONArray jsonArray = jsonarray.getJSONArray(i);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }){
            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                return params;
            }
        };

        // Add the request to the RequestQueue.
        mRequestQueue.add(stringRequest);

继续获取元素

for (int i=0; i<jsonarray.length(); i++) {
    JSONArray elements = element.getJSONObject(i).getJSONArray("elements");
    JSONObject innerObj = elements.getJSONObject(0);
    String distance = innerObj.getJSONObject("distance").getString("text");
    String duration = innerObj.getJSONObject("duration").getString("text");
}
for(int i=0;i
for (int i=0; i<jsonarray.length(); i++) {
    JSONArray elements = element.getJSONObject(i).getJSONArray("elements");
    JSONObject innerObj = elements.getJSONObject(0);
    String distance = innerObj.getJSONObject("distance").getString("text");
    String duration = innerObj.getJSONObject("duration").getString("text");
}