Quantifying the distance using Google_distance r function

67 views Asked by At

I'm trying to quantify the distance between localities, applying the Google_distance r function. I have run the examples of the Google_distance function, but the distance between localities is missing. The others fields are complete, but not the distance.

I have activated just the distance API from google.

The code is:

key <- "your key here"
set_key(key = key, api = "distance")
google_keys()

df <- google_distance(origins = list(c("Melbourne Airport, Australia"),
                                     c("MCG, Melbourne, Australia"),
                                     c(-37.81659, 144.9841)),
                      destinations = c("Portsea, Melbourne, Australia"),
                      key = key) 


head(df)

$destination_addresses
\[1\] "Portsea VIC 3944, Australia"

$origin_addresses
\[1\] "Melbourne Orlando International Airport (MLB), 1 Air Terminal Pkwy, Melbourne, FL 32901, USA"
\[2\] "Brunton Ave, Richmond VIC 3002, Australia"  
\[3\] "Jolimont, Wellington Cres, East Melbourne VIC 3002, Australia"

$rows
\*\*\* Empty \*\*\*
$status
\[1\] "OK"


Perhaps, I need to turn on others google APIs, but I am not sure which ones. Do you have any idea how I could solve this issue?

All suggestions and improvements are welcome, Thank you very much

1

There are 1 answers

0
Marco On

The problem might be located in your API or settings. Are you sure you selected the correct one? The default code is working for me and returns rows as expected. I used the Distance Matrix API.

df <- google_distance(origins = list(c("Melbourne Airport, Australia"),
                                     c("MCG, Melbourne, Australia"),
                                     c(-37.81659, 144.9841)),
                      destinations = c("Portsea, Melbourne, Australia"),
                      key = key) 


head(df)

$destination_addresses
[1] "Portsea VIC 3944, Australia"

$origin_addresses
[1] "Melbourne Airport (MEL), Melbourne Airport VIC 3045, Australia" "Brunton Ave, Richmond VIC 3002, Australia"                     
[3] "Jolimont, Wellington Cres, East Melbourne VIC 3002, Australia" 

$rows
                                  elements
1 133 km, 133291, 1 hour 41 mins, 6043, OK
2 108 km, 107702, 1 hour 24 mins, 5018, OK
3 108 km, 108451, 1 hour 25 mins, 5074, OK

$status
[1] "OK"