'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
Solution 1:[1]
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |