I am tryng to geolocate a vector making use of the R library Ggmap.
location_google_10000 <- geocode(first10000_string, output = "latlon",
source = "dsk", messaging = FALSE)
The problem is that I am using "dsk" -The data science toolkit API- and therefore it has not rate limits as Google (limites to 2500 coordinates per day). However, when I try to run with a vector that contains more than 2500, it pops the following message:
Error: google restricts requests to 2500 requests a day for non-business use.
I have tried to run the code with dsk with 1000 addresses, and later checking if actually google or dsk api has been used:
> geocodeQueryCheck()
2500 geocoding queries remaining.
So for some reason it does not allow me to use more than 2500 with the "dsk", but I am sure that its not using google.
I just ran into the same issue and found your post. I was able to work around this by setting the client
and signature
values to dummy values, e.g.
geocode(myLocations, client = "123", signature = "123", output = 'latlon', source = 'dsk')
The issue appears to be with this part of the geocode function...
if (length(location) > 1) {
if (userType == "free") {
limit <- "2500"
}
else if (userType == "business") {
limit <- "100000"
}
s <- paste("google restricts requests to", limit, "requests a day for non-business use.")
if (length(location) > as.numeric(limit))
stop(s, call. = F)
userType
is set above in this part of the code...
if (client != "" && signature != "") {
if (substr(client, 1, 4) != "gme-")
client <- paste("gme-", client, sep = "")
userType <- "business"
}
else if (client == "" && signature != "") {
stop("if signature argument is specified, client must be as well.",
call. = FALSE)
}
else if (client != "" && signature == "") {
stop("if client argument is specified, signature must be as well.",
call. = FALSE)
}
else {
userType <- "free"
}
So, if client
and signature
parameters are empty userType
is set to "free" and in turn the limit is set to 2,500. By providing values for these parameters you are seen as a 'business' user with a limit of 100,000. This is a good check if the user is assumed to be using 'Google' as opposed to 'dsk' as the source, but is overzealous if the source is 'dsk' and should probably be overridden. To be simple minded maybe something like...
if (source == "google") {
if (client != "" && signature != "") {
if (substr(client, 1, 4) != "gme-")
client <- paste("gme-", client, sep = "")
userType <- "business"
}
else if (client == "" && signature != "") {
stop("if signature argument is specified, client must be as well.",
call. = FALSE)
}
else if (client != "" && signature == "") {
stop("if client argument is specified, signature must be as well.",
call. = FALSE)
}
else {
userType <- "free"
}
} else {
userType <- "business"
}
That would cause problems if client
or signature
parameters were planned for other sources though. I'll ping the package author.