0

I am trying to use very well written instructions from this blog: https://www.jessesadler.com/post/geocoding-with-r/ to geocode locational data in R including specific cites and cities in Hawaii. I am having issues pulling information from Google. When running mutate_geocode my data runs but no output is gathered. I bypassed this for the time being with manual entry of lat and lon for just one location of my dataset, attempting to trouble shoot. Now, when I use get_googlemap, I get the error message "Error in Download File"

I have tried using mutate_geocode as well as running a loop using geocode. I either do not get output or I get the OVER_QUERY_LIMIT error (which seems to be very classic). After checking my query limit I am nowhere near the limit.

Method 1:

BH <- rename(location, place = Location)
BH_df <- as.data.frame(BH)
location_df <- mutate_geocode(HB, Location)

Method 2:

origAddress <- read.csv("HSMBH.csv", stringsAsFactors = FALSE)
geocoded <- data.frame(stringsAsFactors = FALSE)
for(i in 1:nrow(origAddress))
{
  result <- geocode(HB$Location[i], output = "latlona", source = "google")
  HB$lon[i] <- as.character(result[1])
  HB$lat[i] <- as.character(result[2])
  HB$geoAddress[i] <- as.character(result[3])
}

Post Manual Entry of lon and lat points I run in to this error:

map <- get_googlemap(center = c(-158.114, 21.59), zoom = 4)

I am hoping to gather lat and lon points for my locations, and then be able to use get_googlemap to draft a map with which I can plot density points of occurrences (I have the code for the points already).

OTStats
  • 1,820
  • 1
  • 13
  • 22
  • I believe that API now requires you to register for an API key and possibly give a credit card number, though they give you a $200 credit each month. It's been a few months, though, so it may have changed again. – alistaire Jan 16 '19 at 05:06
  • @alistaire, thats why I thought, do you know at what point they will start charging you, is it after a certain number of queries? – Cole Hendrickson Jan 16 '19 at 05:36
  • Last I looked, it gives you a $200 credit each month and charges for everything, so if you go over $200 worth of calls, you actually have to pay. You can set restrictions so it won't go over if you like, and $200 of API calls is quite a lot, depending on what you're trying to do. – alistaire Jan 17 '19 at 16:21
  • @ColeHendrickson You get charged mostly by [number of requests](https://i.stack.imgur.com/8sJna.png). The [pricing](https://cloud.google.com/maps-platform/pricing/sheet/) is quite transparent. I wrote a [step-by-step](https://stackoverflow.com/a/52617929/9406040) tutorial earlier, maybe that helps to get it up and running. – Roman Jan 24 '19 at 10:43

1 Answers1

0

Alternatively, you can use a one-liner for rapid geocoding via tmaptools::geocode_OSM():

Data

library(tmaptools)
addresses <- data.frame(address = c("New York", "Berlin", "Huangpu Qu", 
                                    "Vienna", "St. Petersburg"), 
                                    stringsAsFactors = FALSE)

Code

result <- lapply(addresses[, 1], geocode_OSM)

> result 
$address
           query      lat       lon  lat_min  lat_max   lon_min   lon_max
1       New York 40.73086 -73.98716 40.47740 40.91618 -74.25909 -73.70018
2         Berlin 52.51704  13.38886 52.35704 52.67704  13.22886  13.54886
3     Huangpu Qu 31.21823 121.48030 31.19020 31.24653 121.45220 121.50596
4         Vienna 48.20835  16.37250 48.04835 48.36835  16.21250  16.53250
5 St. Petersburg 27.77038 -82.66951 27.64364 27.91390 -82.76902 -82.54062

This way, you have both

  1. the centroids (lon, lat) that are important for Google Maps and
  2. boundary boxes (lon_min, lat_min, lon_max, lat_max) that mapping services like OSM or Stamen need.
Roman
  • 4,744
  • 2
  • 16
  • 58