Gmapsdistance函数不接受出发时间

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

我正在尝试为gmapsdistance函数提供一系列路由。以前在其他路线上都可以正常使用,但是不接受使用lat和long的组合来使用arrival_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!
r google-maps google-maps-api-3 google-distancematrix-api
1个回答
0
投票

这与错误指示过去的departure_time设置无关。实际上,这似乎是由于origindestination以及dep_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

截至目前对我有什么回报:

$Time
[1] 16842

$Distance
[1] 337527

$Status
[1] "OK"

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.