Not sure why I keep getting this error:
Error in value[3L] : There was an error downloading results. Please manually check the following URL is valid by entering it into a browswer. If valid, please file a bug report citing this URL (note: your API key has been removed, so you will need to add that back in)
#A look at my dataframe called subset:
ID<- c("XM-7393","XM-7138")
Address<- c("175 College St #450, Toronto, ON M5T 1P7" ,"250 College St, Toronto, ON M5T 1R8")
subset<-data.frame(ID,Address)
subset$Address<- as.character(subset$Address)
require(googleway) #using google to get coordinates
gkey<-"INSERT GOOGLE API KEY HERE" #google API Key needed to get lat/lon coordinates
#a lat and lon vector to store the coordinates from the geocode
lat = vector("numeric", length = nrow(subset))
lng = vector("numeric", length = nrow(subset))
#Function for batch geocoding a list of addresses in a dataframe
for (i in 1:nrow(subset)) {
coord = googleway::google_geocode(subset$Address[i], key=gkey)
if (coord$status == "OK") {
coord = googleway::geocode_coordinates(coord)
lat[i] = coord$lat[1] # sometimes returns multiple coordinates
lng[i] = coord$lng[1] # sometimes returns multiple coordinates
} else {
lat[i] = NA
lng[i] = NA
}
}
#adding the lat and lon coordinates to subset dataset
subset$lat = lat
subset$lng = lng
Ok the code above works! But only if the data set does not have that many observations. The original dataset I was working with had 1000 observations and I know that I am not near my API limit. So not to sure why it won't work for when I have a 1000 observation dataset.
ANSWER: Some address fields had '#" to represent unit number. This needs to be removed (see comment below!)