The Google API accepts two parameters which influence the selection of matches [1]: "region" uses domains (.lr in case of Liberia) and "bounds" uses a bounding box (long/lat coords) to prioritize certain results.
While geocode()/mutate_geocode() do not expose these explicitly they can probably be added using the "inject" parameter as key-value pairs (see help(geocode)). Hth, Mathias -- Mathias Moser Institute for Economic Geography & GIScience WU Vienna [1] https://developers.google.com/maps/documentation/geocoding/intro#geocoding On Wed, 2020-02-05 at 16:06 +0100, Melanie Graeser wrote: > 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 > > _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo