dkahle / dkahle/ggmap

Request Denied in geocode with API key

Open
#213 14 comments 0 reactions 0 assignees View on GitHub
needs more information
Dominant language
R
Stars
778
Forks
234
PR merge metrics
No merged PRs in 30d

Description

## Reproducible Example

When I run the code behind below get the response ""error_message" : "Requests to this API must be over SSL. Load the API with \"https://\" instead of \"http://\"."," how to change the http request to https in geocode of ggmap
[servico.xlsx](https://github.com/dkahle/ggmap/files/1907205/servico.xlsx)

Example:

```r
setwd("/Users/fsmoura/Desktop/docs/")
library(ggmap)

#Carga de dados
origAddress <- read.csv("servico/servico.csv", header = TRUE, sep = ";")
#Verificamos o tamanho do data set
dim(origAddress)
#View(origAddress)
#Removemos os duplicados
origAddress <- origAddress[!duplicated(origAddress$Empresa), ]
#Verificamos o tamanho do data set
dim(origAddress)
#criamos a variavel de pesquisa
origAddress$addresses <- origAddress$Endereco
#agregamosao endereço o bairro e cidade
origAddress$addresses <- paste(origAddress$Endereco, origAddress$Bairro, "Porto Alegre", sep = " ")
origAddress$addresses <- paste(origAddress$addresses, "&key=MYKEY", sep = "")
#Eliminamos a virgula
origAddress$addresses <- gsub(",", "", origAddress$addresses)
#fazemos o tipecast
origAddress$addresses <- as.character(origAddress$geoAddress)
#verificamos o resultado final
head(origAddress)
#definimoso range da pesquisa
origAddress<- origAddress[1:50000,]
#fazemos a restricao
addresses <- origAddress$addresses
#verificamos o tamanho
length(addresses)
#executamosa funcao
getGeoDetails <- function(address){
geo_reply = geocode(address, output='all', messaging=TRUE, override_limit=TRUE)
answer <- data.frame(lat=NA, long=NA, accuracy=NA, formatted_address=NA, address_type=NA, status=NA)
answer$status <- geo_reply$status

while(geo_reply$status == "OVER_QUERY_LIMIT"){
print("OVER QUERY LIMIT - Pausando as:")
time <- Sys.time()
print(as.character(time))
Sys.sleep(1)
geo_reply = geocode(address, output='all', messaging=TRUE, override_limit=TRUE)
answer$status <- geo_reply$status
}

if (geo_reply$status != "OK"){
return(answer)
}
answer$lat <- geo_reply$results[[1]]$geometry$location$lat
answer$long <- geo_reply$results[[1]]$geometry$location$lng   
if (length(geo_reply$results[[1]]$types) > 0){
answer$accuracy <- geo_reply$results[[1]]$types[[1]]
}
answer$address_type <- paste(geo_reply$results[[1]]$types, collapse=',')
answer$formatted_address <- geo_reply$results[[1]]$formatted_address

return(answer)
}
geocoded <- data.frame()

startindex <- 1

for (ii in seq(startindex, length(addresses))){
print(paste("Trabalhando no item ", ii, " de", length(addresses)))

result = getGeoDetails(addresses[ii])
print(result$status)
result$index <- ii

geocoded <- rbind(geocoded, result)

}
#write.csv(geocoded, "saida2.csv", row.names=FALSE)
geocoded$accuracy <- NULL
geocoded$address_type<-NULL
geocoded$accuracy<-NULL
geocoded$status<-NULL
geocoded$index<-NULL
write.table(geocoded,file="data.csv",sep=";",dec = " ", row.names=FALSE)

}, si = TRUE)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.