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
Example:
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)
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
Example: