Created
October 21, 2022 13:32
-
-
Save jlomako/206173673e08e8ea85cbeba29ad6b975 to your computer and use it in GitHub Desktop.
Create Google Maps links based on coordinates and add links to leaflet markers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to create Google Maps links based on coordinates and add links to leaflet markers | |
library(leaflet) | |
library(htmltools) | |
# create df with coordinates | |
df <- read.csv(textConnection( | |
"name,Lat,Long | |
Parc Lafontaine,45.5273219,-73.5703556 | |
Central Park,40.7812199,-73.9665138" | |
)) | |
# create Google Maps links based on coordinates | |
df$content <- sprintf(paste0("<b>",df$name,"</b><br>", | |
"<a href='https://www.google.com/maps/search/?api=1&query=",df$Lat,"%2C",df$Long,"'>get directions</a>")) %>% | |
lapply(HTML) | |
# add links to leaflet markers | |
leaflet(df) %>% | |
addProviderTiles(providers$OpenStreetMap) %>% | |
addCircleMarkers(lng = ~Long, lat = ~Lat, | |
popup = ~content | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment