我可以从谷歌的距离矩阵API的所有数据放在一个HTTP请求?

问题描述 投票:1回答:1

我使用谷歌距离矩阵API来获取2个坐标之间的行车时间。 这是我得到的数据的方法:

 private void testDistanceApi(String url) throws IOException {
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder()
            .url(url)
            .build();
    Response response = client.newCall(request).execute();
    System.out.println("this is my response --------" +response);
}

这是我得到的回应:

 System.out: this is my response --------Response{protocol=h2, code=200, message=, url=https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=32.002700,%2034.750875&destinations=31.963263,%2034.748292&key=AIzaSyAzFFPgX-GryNpheDClG-PpEr1OGuHm6OY}

response(JSON)存在的URL(你可以在打印看),我想知道如果我可以从网址获得JSON不使用另一个HTTP请求。

从JSON的网址:

url=https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=32.002700,%2034.750875&destinations=31.963263,%2034.748292&key=AIzaSyAzFFPgX-GryNpheDClG-PpEr1OGuHm6OY
android google-distancematrix-api
1个回答
0
投票

我找到了解决办法,我从来没有解析响应为JSON,就没有必要再HTTP请求。我只是解析这样的回应:

    String resStr = response.body().string();
    JSONObject json = new JSONObject(resStr);
    System.out.println("jsonnnnn????" + json);
© www.soinside.com 2019 - 2024. All rights reserved.