tmap (version 1.6-1)

geocode_OSM: Geocodes a location using OpenStreetMap Nominatim


Geocodes a location (based on a search query) to coordinates and a bounding box. Similar to geocode from the ggmap package. It uses OpenStreetMap Nominatim. For processing large amount of queries, please read the usage policy (


geocode_OSM(q, projection = NULL, return.first.only = TRUE, details = FALSE, = NA, as.SPDF = FALSE, server = "")


a character (vector) that specifies a search query. For instance "India" or "CBS Weg 11, Heerlen, Netherlands".
projection in which the coordinates and bounding box are returned. Either a CRS object or a character value. If it is a character, it can either be a PROJ.4 character string or a shortcut. See get_proj4 for a list of shortcut values. By default latitude longitude coordinates.
Only return the first result
provide output details, other than the point coordinates and bounding box
Return the output as a data.frame. If FALSE, a list is returned with at least two items: "coords", a vector containing the coordinates, and "bbox", the corresponding bounding box. By default false, unless q contains multiple queries
Return the output as SpatialPointsDataFrame. If TRUE, return.first.only will be set to TRUE.
OpenStreetMap Nominatim server name. Could also be a local OSM Nominatim server.


If as.SPDF then a SpatialPointsDataFrame is returned. Else, if, then a data.frame is returned, else a list.

See Also

rev_geocode_OSM, bb


Run this code
geocode_OSM("CBS Weg 1, Heerlen")
geocode_OSM("CBS Weg 1, Heerlen", projection = "rd")

## Not run: 
# data(metro)
# five_cities <- metro[sample(length(metro), 5), ]
# locations <- geocode_OSM(five_cities$name_long)
# five_cities <- append_data(five_cities, locations, fixed.order = TRUE)
# five_cities2 <- five_cities@data
# sp::coordinates(five_cities2) <- ~lon+lat
# tmap_mode("view")
# tm_shape(five_cities) +
# 	tm_dots(col = "blue") +
# tm_shape(five_cities2) +
# 	tm_dots(col = "red")
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace