Gmapsdistance 函数不接受出发时间

Gmapsdistance function not accepting departure times

我正在尝试为 gmapsdistance 函数提供一系列路线。这以前在其他路线上运行良好,但不接受 departure_time 经纬度组合的参数。

我曾尝试简单地以字符格式输入未来时间 ("20:00:00"),但得到了同样的错误。

route_1 <- c(c(57.14748,-2.0954), c(51.12788,-4.25714))
route_2 <- c(c(55.81875,-4.02555), c(51.4721,-0.45273))
route_3 <- c(c(54.96566,-5.0152), c(55.86568,-4.25714))
route_4 <- c(c(51.12788,-4.25714), c(51.38867,0.193838))
route_5 <- c(c(55.86568,-4.25714), c(51.12788,-4.25714))
route_6 <- c(c(51.4721,-0.45273), c(51.12788,-4.25714))

result <- gmapsdistance(origin = route_6[[1]], route_6[[2]],
                        destination = route_6[[3]], route_6[[4]],
                        traffic_model = "pessimistic",
                        mode = "driving", 
                        dep_date = as.character(Sys.Date()), 
                        dep_time = as.character(Sys.time() + 60*10),
                        key=key,
                        combinations = "all",
                        avoid = "")``

收到的错误很奇怪:

The departure time has to be some time in the future!

这与错误指示的过去设置 departure_time 无关。它实际上看起来像是源于 origin & destinationdep_time.

的无效格式

根据图书馆的docs,坐标格式应该如下:

"38.1621328+24.0029257"

并且出发时间应该只包含时间,而不是日期+时间。例如:

"20:40:00"

请尝试 运行 下面的完整代码(使用您的 API 密钥):

library("gmapsdistance")

set.api.key("AIza...")

route_6 <- c(c("51.4721+-0.45273"), c("51.12788+-4.25714"))

results = gmapsdistance(origin = route_6[[1]],
                        destination = route_6[[2]],
                        traffic_model = "pessimistic",
                        mode = "driving", 
                        dep_date = as.character(Sys.Date()), 
                        dep_time = as.character(format(Sys.time() + 60*10, "%H:%M:%S")),
                        key=get.api.key(),
                        combinations = "all",
                        avoid = "")
results

目前对我来说returns:

$Time
[1] 16842

$Distance
[1] 337527

$Status
[1] "OK"

希望对您有所帮助!