trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
216 stars 74 forks source link

Geocoding using Leaflet-search #47

Closed JacHansel closed 7 years ago

JacHansel commented 7 years ago

Hi,

I would like to do geocoding using Leaflet-search in R (something like this: http://labs.easyblog.it/maps/leaflet-search/examples/nominatim.html).

However, I couldn't find anything like this in the R-examples (only in JS).

Could you help me with this issue?

Thanks!

bhaskarvk commented 7 years ago

Did you try addOSMSearch() ?

JacHansel commented 7 years ago

Thanks for your quick reply.

I just tried it, do I have to install something for it? And can it be used in R?

bhaskarvk commented 7 years ago

You don't have to install anything besides leaflet.extras package. What happens when you call addOSMSearch().

JacHansel commented 7 years ago

I get the following error message: could not find function "addOSMSearch"

bhaskarvk commented 7 years ago

Sorry the function name is addSearchOSM

If you've not already installed leaflet.extras and loaded it, do the following.

devtools::install_github('rstudio/leaflet')
devtools::install_github('bhaskarvk/leaflet.extras')
library(leaflet.extras)
JacHansel commented 7 years ago

Thanks, it is working now and this is exactly what I was looking for! Is there any documentation available for this function?

bhaskarvk commented 7 years ago

https://bhaskarvk.github.io/leaflet.extras/search.html. TBH there is not much to document about this function. It doesn't take any arguments or anything. All leaflet.extras functions are properly documented and you can access the help using R's ? operator. e.g. ?addSearchOSM.

For online ref. see https://bhaskarvk.github.io/leaflet.extras/reference.html

JacHansel commented 7 years ago

Thank you so much for all your help!

When using the function locally, it is working fine, but when I deploy my app (I am using Shiny), the function is not working anymore. Do you have any idea what the reason for this could be?

bhaskarvk commented 7 years ago

To shinyapps.io ? or any other shiny server ? I'll try to replicate it on my side, but any error or warning messages you can provide will be helpful.

JacHansel commented 7 years ago

Yes, I want to deploy the app to shinyapps.io. Sorry for being imprecise.

I use the following code, which is working fine when I run it locally:

output$map <- renderLeaflet({
leaflet() %>%
addSearchOSM(options = searchOSMOptions(zoom=15, position = 'topleft')) %>%
addTiles()
})

However, when I deploy it to shinyapps.io, the addSearchOSM()-function is not working anymore (see https://streetnaturescore.shinyapps.io/shiny_app/). I don't get any warning or error message. The search box still shows up in the app, but when you type in an address, it seems like it is not searching.

bhaskarvk commented 7 years ago

ok cool I will debug it at my end.

bhaskarvk commented 7 years ago

I fixed the issue please retest.

Jaimeolivares commented 7 years ago

Hi,

Would just like to report the reverse. When attempting to use the search function on a locally saved map, the search box still shows up in the app, but when you type in an address, it seems like it is not searching.

However, when i use the old url: "url = 'http://nominatim.openstreetmap.org/search?format=json&q={s}'", the function works when saved locally.

Hope this helps. Great work on the extra functions. They are very helpful!

bhaskarvk commented 7 years ago

Yes we have that issue with the OSM tiles added via addTiles() too. Nothing much we can do about it but properly document it, I guess. Thanks for reporting, I will add that to the help text.