2

I was using google map API to get the coordinates for Fortune500 companies with geoocode However, when I ran it, it still showed OVER_QUERY_LIMIT periodically and thus my geocode list is not complete. So I have 2 questions:

  1. how to get all the geocodes(was my code wrong)?
  2. how to edit my API key in R environment & source it in my code?

To get Fortune500 list:

    library(XML)
    library(RCurl)
    fortune500_url <- getURL("https://www.geolounge.com/fortune-500-list-by-
    state-for-2015/",.opts = list(ssl.verifypeer = FALSE) ) 
    fortune500 = readHTMLTable(fortune500_url, header = TRUE, which = 1)
    colnames(fortune500) <- tolower(colnames(fortune500))
    fortune500 <- 
    subset(fortune500,select=c("company","streetadd","place","state","zip"))
    write.csv(fortune500, "fortune500.csv")

Trouble getting coordinates for all Fortune500 companies in the following:

    # Add API key to renviron file
    usethis::edit_r_environ() # how do we assign API key to a variable?

    # Install Developer version of ggmap to use maps API Key

    devtools::install_github("dkahle/ggmap")
    library(ggmap)

    register_google(key = Sys.getenv("MY_API_KEY")) # how to source my key from R environment ?

    fortune500$address <- paste(fortune500$streetadd, fortune500$place, 
    fortune500$state, fortune500$zip)

    geocodes <- geocode(fortune500$address, output = "latlon" , source = 
    "google")    # can't get all coordinates

Thank you for your help.

Edward Lin
  • 609
  • 1
  • 9
  • 16
  • 1
    If you have the addresses of the companies, then this might help you: https://stackoverflow.com/questions/32504880/street-address-to-geolocation-lat-long – niko Mar 05 '18 at 12:59
  • 1
    You're not the first to have issues with `ggmap`s key registration. Similar [question here](https://stackoverflow.com/questions/34402979/increase-the-api-limit-in-ggmaps-geocode-function-in-r) and [here](https://stackoverflow.com/q/49108756/5977215). I can recommend my `googleway` package for all your google API requirements :) – SymbolixAU Mar 05 '18 at 21:26
  • actually, I figured out the problem. I could apply for a free gmap API here: Get API Key here: https://developers.google.com/maps/documentation/geocoding/get-api-key the problem was I didn't stored and sourced the API key correctly. Thanks for your help! – Edward Lin Mar 06 '18 at 22:56
  • 1
    Can you post this as a comment and accept it? – Roman Dec 24 '18 at 21:16

0 Answers0