Reputation: 11
Have an R script to run a bunch of different points for commute time and distance. Have a google API key with an enabled billing account, go to run and get shut down at line 262 every time.
Tried restructuring the code. Refreshed the API Set the API key in different parts
Code works perfect up to that point, and it is making a connection with google as it is showing in the API.
emp_commute$CommuteTime[i] <- gmapsdistance(origin = emp_commute$HomeComplete[i],
destination = emp_commute$WorkComplete[i],
mode = "driving",
key = "",
arr_date = "2019-11-13",
arr_time = emp_commute$ArrivalTime[i])$Time[1]
Error in gmapsdistance(origin = emp_commute$HomeComplete[i], destination = emp_commute$WorkComplete[i], : Google API returned an error: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account
Googled and googled, just would love some advice!
Upvotes: 1
Views: 2651
Reputation: 33
I found the issue: It is when there is a # in the address (e.g., 123 Main St Apt #6).
If you remove the :Apt #6", so it is just "123 Main St", then it works fine.
Upvotes: 0
Reputation: 5701
This package works without problem for me. Used RStudio Cloud. Here's what I did.
First I installed gmapsdistance:
install.packages("gmapsdistance")
Then I ran the following code with my API key (set in the key=
parameter):
library("gmapsdistance")
origin <- c("40.431478+-80.0505401", "33.7678359+-84.4906438")
destination <- c("43.0995629+-79.0437609", "41.7096483+-86.9093986")
results <- gmapsdistance(origin, destination, mode="driving", key="abcd", arr_date="2019-11-13", arr_time="09:00:00")
results
The response was:
$Time
or Time.43.0995629+-79.0437609 Time.41.7096483+-86.9093986
1 40.431478+-80.0505401 13878 23071
2 33.7678359+-84.4906438 49402 38351
[...]
Using set.api.key("")
also worked fine. For testing purposes I recommend that you try my exact steps and code above. Also double check the following:
origin
, destination
and arr_time
are valid (try hard-coding them first)Hope this helps.
Upvotes: 0