Skip to content

Instantly share code, notes, and snippets.

@Jian-Qiao
Created August 22, 2017 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jian-Qiao/5bc9cc30ada1109aa069d6dfc38009ae to your computer and use it in GitHub Desktop.
Save Jian-Qiao/5bc9cc30ada1109aa069d6dfc38009ae to your computer and use it in GitHub Desktop.
#Scrape Event Location Data
#-----------------------------------------------------------------------------------------------------------------------------
Stadiums=count(EventsInfo$X3)
Stadiums$x=as.character((Stadiums$x))
geoCodeDetails = 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 - Pausing for 1 hour at:')
time=sys.time()
print(as.character(time))
sys.sleep(60*60)
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$result[[1]]$geometry$location$lat
answer$long=geo_reply$result[[1]]$geometry$location$lng
if (length(geo_reply$result[[1]]$types)>0){
answer$accuracy=geo_reply$result[[1]]$types[[1]]
}
answer$address_type=paste(geo_reply$result[[1]]$types,collapse=',')
answer$formatted_address=geo_reply$result[[1]]$formatted_address
return(answer)
}
Stadiums$lat=NA
Stadiums$long=NA
for (i in seq(1,nrow(Stadiums))){
Detail=geoCodeDetails(Stadiums$x[i])
Stadiums$lat[i]=Detail$lat
Stadiums$long[i]=Detail$long
Stadiums$Address=Datail$formatted_address
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment