计算路由:(列表)对象无法强制键入'double

时间:2017-05-31 13:37:19

标签: r

我有一个开始和结束坐标的df。我正在尝试计算一小部分df的完整路线,大约300次。 ggmap route函数开始但在大约12次路由计算后遇到错误。错误是(列表)对象无法强制键入'double'。我该如何在代码中解决这个问题?我在下面的链接中有一个csv数据供任何人测试。

总体最终目标是像http://flowingdata.com/2014/02/05/where-people-run/这样的产品,可视化所有路线。

ggplot2

这是错误

library(tidyverse)
library(ggmap)
feb_14 <- read.csv('https://raw.githubusercontent.com/smitty1788/Personal-Website/master/dl/CaBi_Feb_2017.csv', stringsAsFactors = FALSE)


start<-c(feb_14[1:300, 14])
dest<-c(feb_14[1:300, 15])


routes <- tibble(
  start,
  dest)

calculationroute <- function(startingpoint, stoppoint) {
  route(from = startingpoint,
        to = stoppoint,
        mode = 'bicycling',
        structure = "route")}

calculatedroutes <- mapply(calculationroute,
                           startingpoint = routes$start,
                           stoppoint = routes$dest,
                           SIMPLIFY = FALSE)

do.call(rbind.data.frame, lapply(names(calculatedroutes), function(x) {
  cbind.data.frame(route=x, calculatedroutes[[x]], stringsAsFactors=FALSE)
})) -> long_routes

1 个答案:

答案 0 :(得分:1)

错误与Google API有关。我达到了每秒的速率限制。简单的解决方法是添加一个Sys.Sleep来降低通话速率。

calculationroute <- function(startingpoint, stoppoint) {
 Sys.sleep(1)
  route(from = startingpoint,
        to = stoppoint,
        mode = "bicycling",
        structure = "route")}