[R-sig-Geo] Geocoding addresses restricted to one country

Melanie Graeser me|gr@e@er @end|ng |rom gm@||@com
Wed Feb 5 16:06:08 CET 2020


Dear users,

I am trying to geocode locations of firms in Liberia from a vector of
addresses. My problem is that many addresses are not geocoded in
Liberia, but instead all over the world. I would like to restrict the
API geocoding response to only show results that are in Liberia. I am
using the Google API and library(ggmap). My code is the following:

register_google(key = "myAPIkey")

test <- mutate_geocode(nec07, Address) # nec07 is my df of firms,
Address is a vector of firm addresses

test1<-test %>% drop_na(lon) # dropping all NAs where geocoding
returned no result to be able to create sf object to see if locations
are correctly geocoded

test1_sf <- st_as_sf(test1, coords = c("lon", "lat"), crs = 4326)

mapview(test1_sf) # Only 2000 out of 5000 firms are geocoded in
Liberia, the rest in other countries

I would be very grateful if you know of any options to restrict
geocoding to return locations only in Liberia.

Many thanks in advance!

Melanie

-- 
Melanie Gräser
*Research Associate*
*Vienna University of Economics and Business*



More information about the R-sig-Geo mailing list