I would like to insert the same Markers
from the graph generated by leaflet
(first graph) in the graph generated by googleway
(second graph). Note that the route between the two points is generated in the second graph, but it does not have the Markers
of the first graph. So, can you help me adjust the code below so that the Markers
appear in the second graph as well?
Code executable below:
library(dplyr)
library(geosphere)
library(shinythemes)
library(leaflet)
library(googleway)
set_key( "API KEY")
df<-structure(list(Properties = c(1, 2, 3, 4, 5, 6, 7), Latitude = c(-23.8,
-23.8, -23.9, -23.9, -23.9, -23.4, -23.5), Longitude = c(-49.6,
-49.3, -49.4, -49.8, -49.6, -49.4, -49.2),
cluster = c(1L, 2L, 2L, 1L, 1L, 3L,3L)), row.names = c(NA, -7L), class = "data.frame")
df1<-structure(list(Latitude = c(-23.8666666666667, -23.85, -23.45
), Longitude = c(-49.6666666666667, -49.35, -49.3), cluster = c(1,
2, 3)), class = "data.frame", row.names = c(NA, -3L))
df_spec_clust <- df1[df1$cluster == 1,]
df_spec_prop<-df[df$Properties==2,]
# Create icon:
leafIcons <- icons(
iconUrl = ifelse(df1$cluster,
"https://cdn-icons-png.flaticon.com/512/25/25694.png"
),
iconWidth = 30, iconHeight = 40,
iconAnchorX = 25, iconAnchorY = 12)
html_legend <- "<img src='https://cdn-icons-png.flaticon.com/512/25/25694.png'>"
#Color and Icon for map
ai_colors <-c("red","gray","blue","orange","green")
clust_colors <- ai_colors[df$cluster]
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = clust_colors)
LEAFLET
m1<-leaflet(df_spec_clust) %>% addTiles() %>%
addMarkers(~Longitude, ~Latitude,icon = leafIcons) %>%
addAwesomeMarkers(leaflet(df_spec_prop) %>% addTiles(), lat=~df_spec_prop$Latitude, lng = ~df_spec_prop$Longitude, icon= icons)
m1
GOOGLE MAPS
df2<-google_directions(origin = df_spec_clust[,1:2],
destination = df_spec_prop[,2:3], mode = "driving")
df_routes <- data.frame(polyline = direction_polyline(df2))
m2<-google_map() %>%
add_polylines(data = df_routes, polyline = "polyline")
m2