Googleway 不考虑旅行时间的交通(路线搜索)
Googleway not considering traffic for travel time (directions search)
使用 googleway
包中的 google_directions
函数,它不会根据 google 地图浏览器搜索显示旅行时间。
好像没有考虑路况信息
纽约繁忙街道上的示例。
a <- google_directions(origin = c(40.862804, -73.934743),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
units = "metric",
simplify = TRUE,
key = MY_API)
当前时间响应:
b <- direction_steps(a)
total_time <- sum(b$duration$value)/60 # minutes
total_time # minutes
#[1] 26.1166
但是,google 地图浏览器显示相同搜索时间的 35 分钟。我查了一下路线,都是一样的。
使用 mapsapi
包会发生同样的事情:
c <- mp_directions(origin = c(-73.934743,40.862804),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
key = MY_API)
total_time1 <- sum(mp_get_segments(c)$duration_s)/60 # minutes
total_time1 # minutes
# [1] 26.11667
有谁知道如何将交通信息整合到这些功能中?或者我应该断定 google 没有提供这种级别的信息?
google_directions
的 googleway
文档涵盖了这一点。要获取实时数据,您需要具备以下条件:
- a
departure_time
,当前使用 "now"
或使用 POSIXct
日期时间的指定未来时间。
traffic_model
:Google的猜测是否应该是best_guess
、optimistic
或pessimistic
。
您使用代码请求历史旅行时间,而 Google 地图使用实时旅行时间(可能是 best_guess
估计值)。
The Google documentation states:
best_guess
(default) indicates that the returned duration_in_traffic
should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the departure_time
is to now.
试试这个:
a <- google_directions(
origin = c(40.862804, -73.934743),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
units = "metric",
simplify = TRUE,
key = MY_API,
departure_time = "now",
traffic_model = "best_guess")
# Travel time in seconds
travel_time <- a$routes$legs[[1]]$duration_in_traffic$value
使用 googleway
包中的 google_directions
函数,它不会根据 google 地图浏览器搜索显示旅行时间。
好像没有考虑路况信息
纽约繁忙街道上的示例。
a <- google_directions(origin = c(40.862804, -73.934743),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
units = "metric",
simplify = TRUE,
key = MY_API)
当前时间响应:
b <- direction_steps(a)
total_time <- sum(b$duration$value)/60 # minutes
total_time # minutes
#[1] 26.1166
但是,google 地图浏览器显示相同搜索时间的 35 分钟。我查了一下路线,都是一样的。
使用 mapsapi
包会发生同样的事情:
c <- mp_directions(origin = c(-73.934743,40.862804),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
key = MY_API)
total_time1 <- sum(mp_get_segments(c)$duration_s)/60 # minutes
total_time1 # minutes
# [1] 26.11667
有谁知道如何将交通信息整合到这些功能中?或者我应该断定 google 没有提供这种级别的信息?
google_directions
的 googleway
文档涵盖了这一点。要获取实时数据,您需要具备以下条件:
- a
departure_time
,当前使用"now"
或使用POSIXct
日期时间的指定未来时间。 traffic_model
:Google的猜测是否应该是best_guess
、optimistic
或pessimistic
。
您使用代码请求历史旅行时间,而 Google 地图使用实时旅行时间(可能是 best_guess
估计值)。
The Google documentation states:
best_guess
(default) indicates that the returnedduration_in_traffic
should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer thedeparture_time
is to now.
试试这个:
a <- google_directions(
origin = c(40.862804, -73.934743),
destination = "212 5th Ave, New York, NY 10010, USA",
mode = "driving",
units = "metric",
simplify = TRUE,
key = MY_API,
departure_time = "now",
traffic_model = "best_guess")
# Travel time in seconds
travel_time <- a$routes$legs[[1]]$duration_in_traffic$value