RScript: Add Multiple Circle Marker in Leaflet

21 Views Asked by At

I want to add multiple circle markers on my leaflet map. The data I'm using is from waze data feed. The line(or location) data is list of arrays, I'm using a for loop to get and put it on my map.

Here is my code:

library(jsonlite)
library(tidyverse)
library(leaflet)

# download waze data feeds
data <- fromJSON("https://www.waze.com/row-partnerhub-api/partners/11262491165/waze-feeds/8d2cefb6-9636-402c-adb1-be2977117f2d?format=1", flatten = TRUE)

# get number of line
line <- length(data$jams$line)

# add map and marker
for (i in 1:line) {
  dfline <- as.data.frame(data$jams$line[i])
  leaflet(dfline) %>% addTiles() %>%
    addCircleMarkers(lng = ~x, lat = ~y, color = "red")
}

There is no error shown, but it won't work. It's not even showing a map.

Here is the sample data.

enter image description here

I am very greatful of any help. Thank you for reading.

0

There are 0 best solutions below