Recently, I have been using OpenStreetMap for some of my R projects and ran into a peculiar issue.
Just as a background, I have been playing around with the R package Nominatim and wanted to do some plotting using R. I kept on getting this error – Please provide a openstreet API key.
Turns out that Nominatim uses the MapQuest Nominatim API and that Nominatim has a usage policy which allows some requests for creative and unexpected uses. Basically, you access the openstreetmap API, for which you need a valid API key.
Install the package:
install.packages('OpenStreetMap') or devtools::install_github("hrbrmstr/nominatim")
Invoke the package in R
You can get the API key for free at https://developer.mapquest.com
If you do not use an API key, you will get an error – “Please provide a openstreet API key”
Use the openstreet key in your R code like this:
reverse_geocode_coords(lat = 35.65858, lon = 139.74545, key =“PUT_YOUR_KEY_HERE”)
Or in a vector:
osm_geocode(c("1600 Pennsylvania Ave, Washington, DC.","1600 Amphitheatre Parkway, Mountain View, CA", "Seattle, Washington"), key ="PUT_YOUR_KEY_HERE")
There are so many amazing things that you can do with this package:
address_lookup: Lookup the address of one or multiple OSM objects osm_geocode: Search for places by address osm_search: Search for places osm_search_spatial: Search for places' reverse_geocode_coords: Reverse geocode based on lat/lon reverse_geocode_osm: Reverse geocode based on OSM Type & Id bb_lookup: Bounding box (and other metadata) lookup