Skip to content
Switch branches/tags
Go to file


Failed to load latest commit information.
Latest commit message
Commit time


CRAN Status CRAN Checks CRAN Downloads per Month R-CMD-check rOpenSci Peer-Review License

Geocode with the OpenCage API, either from place name to longitude and latitude (forward geocoding) or from longitude and latitude to the name and address of the location (reverse geocoding).


Install the package with:


Or install the development version using remotes with:



For the best experience, we recommend that you read through the “Introduction to opencage” vignette (vignette("opencage")), but if you are in a hurry:

  1. Register at
  2. Generate an API key at the OpenCage dashboard.
  3. Save your API key as an environment variable like OPENCAGE_KEY=yourkey in .Renviron. See help(oc_config) for alternative ways to set your OpenCage API key.

Now you are ready to turn place names into latitude and longitude coordinates:

oc_forward_df(placename = "Sarzeau")
## # A tibble: 1 x 4
##   placename oc_lat oc_lng oc_formatted         
##   <chr>      <dbl>  <dbl> <chr>                
## 1 Sarzeau     47.5  -2.76 56370 Sarzeau, France

Or turn a set of coordinates into the name and address of the location:

oc_reverse_df(latitude = 51.5034070, longitude = -0.1275920)
## # A tibble: 1 x 3
##   latitude longitude oc_formatted                                               
##      <dbl>     <dbl> <chr>                                                      
## 1     51.5    -0.128 Prime Minister’s Office, Westminster, 10 Downing Street, L~

But remember, the vignettes are really great! We have:

  • “Introduction to opencage” vignette("opencage")
  • “Customise your query” vignette("customise_query")
  • “Output options” vignette("output_options")

About OpenCage

The OpenCage API supports forward and reverse geocoding. Sources of OpenCage are open geospatial data including OpenStreetMap, DataScienceToolkit, GeoPlanet, Natural Earth Data, libpostal, GeoNames, and Flickr’s shapefiles plus a whole lot more besides. Refer to the current full list of credits.


  • Please report any issues or bugs.
  • License: GPL >= 2
  • Get citation information for opencage in R doing citation(package = 'opencage')
  • Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.