How do I get ggmap route data to follow road path
The answer was to place the decodeLine function into the do.call to create the long routes dataframe
decodeLine <- function(encoded){ require(bitops) vlen <- nchar(encoded) vindex <- 0 varray <- NULL vlat <- 0 vlng <- 0 while(vindex < vlen){ vb <- NULL vshift <- 0 vresult <- 0 repeat{ if(vindex + 1 <= vlen){ vindex <- vindex + 1 vb <- as.integer(charToRaw(substr(encoded, vindex, vindex))) - 63 } vresult <- bitOr(vresult, bitShiftL(bitAnd(vb, 31), vshift)) vshift <- vshift + 5 if(vb < 32) break } dlat <- ifelse( bitAnd(vresult, 1) , -(bitShiftR(vresult, 1)+1) , bitShiftR(vresult, 1) ) vlat <- vlat + dlat vshift <- 0 vresult <- 0 repeat{ if(vindex + 1 <= vlen) { vindex <- vindex+1 vb <- as.integer(charToRaw(substr(encoded, vindex, vindex))) - 63 } vresult <- bitOr(vresult, bitShiftL(bitAnd(vb, 31), vshift)) vshift <- vshift + 5 if(vb < 32) break } dlng <- ifelse( bitAnd(vresult, 1) , -(bitShiftR(vresult, 1)+1) , bitShiftR(vresult, 1) ) vlng <- vlng + dlng varray <- rbind(varray, c(vlat * 1e-5, vlng * 1e-5)) } coords <- data.frame(varray) names(coords) <- c("lat", "lon") coords}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, decodeLine(calculatedroutes[[x]]$routes[[1]]$overview_polyline$points), stringsAsFactors=FALSE)})) -> long_routes