Error on using google_distance with mutate

92 views Asked by At

I'm trying to calculate the driving distance between two coordinate locations. Here's my code:

library(tidyverse)
library(googleway)

distances %>%
  mutate(distance = google_distance(origins = origin, destinations = destination, key = 'API KEY'))

Here's my dataset - https://pastebin.com/d6Z6b2K5

I get this error:

Error in mutate():
! Problem while computing distance = google_distance(...).
✖ distance must be size 294 or 1, not 5.

I'd really appreciate some help with this!

1

There are 1 answers

1
Umair Shariff On

Here's the solution that worked for me

mutate(distance = purrr::map2(origin, destination, ~ google_distance(.x, .y, key = 'API KEY')))