gpt4 book ai didi

java - 如何使用 "departure_time"作为参数通过距离矩阵 api 将 future 时间传递到 HTTP 请求中

转载 作者:行者123 更新时间:2023-11-29 23:19:36 26 4
gpt4 key购买 nike

我正在使用 distant matrix api为了获得 2 点之间的旅行时间,我想在计算旅行时间时考虑交通情况,我在将此 URL 作为请求的一部分传递时调用距离矩阵:

"https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&" +
"origins=" + startLat +"," + startlong +
"&destinations=" + endLat +","+endLong +
//departure_time parameter
"&departure_time=now" +
"&key=my api key");

根据文档,将 departure_time 参数添加到我的请求将在考虑交通时添加旅行时间数据(在上面的 URL 中,我在发送请求时使用该参数)。

我想将 future 的一些时间作为 departure_time 参数传递
阅读文档后,我似乎需要将时间作为 int/long 传递,(例如 departure_time=1399995076)。

这里有一些时间,例如 = 21:15 让我们说在星期五。

如何将这个时间或任何时间转换成 int/long?

我看过this answer还有更多与该主题相关的内容,但没有一个对我有帮助。

最佳答案

出发时间需要以毫秒为单位的时间,要获得以毫秒为单位的当前时间,您需要使用 System.currentTimeMillis()。如果您需要将来的时间,请添加以毫秒为单位的小时数,例如, future 1 小时是 3600000 毫秒,因此请使用 System.currentTimeMillis() + 3600000

所以在你的代码中它看起来像这样:

Long future_time = System.currentTimeMillis() + 3600000;
"https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&" +
"origins=" + startLat +"," + startlong +
"&destinations=" + endLat +","+endLong +
//departure_time parameter
"&departure_time=" + future_time +
"&key=my api key");

关于java - 如何使用 "departure_time"作为参数通过距离矩阵 api 将 future 时间传递到 HTTP 请求中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54608214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com