Skip to contents

Adds a geocoding search widget to a leaflet map using the leaflet-geosearch plugin. Supports multiple providers such as OpenStreetMap, Esri, Google, HERE, etc.

Usage

addGeosearch(map, provider = geosearchProvider(), options = geosearchOptions())

Arguments

map

a map widget

provider

A provider list object created with e.g. geosearchProvider

options

A list of control options created with geosearchOptions.

Value

the new map object

Shiny value

When used inside a Shiny application, addGeosearch() will also register two reactive inputs that return the most recent geosearch results:

  • input$<mapId>_geosearch_result Updated when a search result is selected (from the geosearch/showlocation event). Returns a list with lat, lng, label, bounds, and other properties provided by the geocoder.

  • input$<mapId>_geosearch_dragend Updated when the marker placed by the geosearch control is dragged to a new location (from the geosearch/marker/dragend event). Returns the same structure as above.

Both values are NULL if no result is available.

See also

Other Geosearch Functions: geosearchOptions(), removeGeosearch()

Examples

library(leaflet)
library(leaflet.extras2)

leaflet() %>%
  addTiles() %>%
  addGeosearch()