简体   繁体   中英

How to use location marking in leaflet package in R

I have added two markers on leaflet map, and I want to link those markers (like travelling from one location to the other). How can I do that?

The code that I used to create markers is provided below:

p <- leaflet()
p <- p %>%
  addTiles()
p <- p %>% 
  addMarkers(lat = 32.051960, lng = 118.778030)
p <- p %>%
  addMarkers(lat = 33.6028, lng = 73.0646)
p

You can use the gcIntermediate function from the geosphere package to create curved lines in leaflet . You can use the following code:

library(leaflet)
library(dplyr)
library(geosphere)
gcIntermediate(c(118.778030, 32.051960), c(73.0646, 33.6028),
               n=100, 
               addStartEnd=TRUE,
               sp=TRUE) %>% 
  leaflet() %>% 
  addTiles() %>% 
  addMarkers(lat = 32.051960, lng = 118.778030) %>%
  addMarkers(lat = 33.6028, lng = 73.0646) %>%
  addPolylines()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM