我可以在一个 HTTP 请求中从 google 距离矩阵 api 获取所有数据吗?

Can i get all the data from google distance matrix api in one HTTP request?

我正在使用 google 距离矩阵 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 来自 URL 而不使用另一个 HTTP 请求。

来自JSON的URL:

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

我找到了解决方案,我从未将响应解析为 JSON,不需要另一个 HTTP 请求。我只是像这样解析了响应:

    String resStr = response.body().string();
    JSONObject json = new JSONObject(resStr);
    System.out.println("jsonnnnn????" + json);