Shiny, leaflet & addSearchOSM : how to retrieve lat/long

I have a leaflet map inside a Shiny app. I have JS code that captures the user's location and assigns it to input$lat and input$long. The leaflet map adds a Circle Marker that defaults to the user's location.

The leaflet.extras::addSearchOSM function adds a search magnifying glass to the map. A user can search an address, and the circle marker will move to that address. What I want to do, is retrieve the latitude and longitude of the searched address, assign lat/long to objects in the workspace, and display in the app. I don't know how to retrieve the lat/long that is geocoded from the OSM address.

output$map <- renderLeaflet({ leaflet() %>% addTiles() %>% addCircleMarkers(lat=input$lat,lng=input$long,radius=10,color='blue') %>% leaflet.extras::addSearchOSM() })

1 Like