library(tidyverse)
library(leaflet)
library(rStrava)
library(sf)
# Get your credentials from https://www.strava.com/settings/api
<- Sys.getenv("STRAVA_APP_NAME")
app_name <- Sys.getenv("STRAVA_CLIENT_ID")
client_id <- Sys.getenv("STRAVA_CLIENT_SECRET")
client_secret
#' Convert Google polylines from Strava activities to {sf} polylines
#'
#' @param gp string : encoded polyline
#'
#' @return {sf} polyline
<- function(gp) {
gp2sf |>
gp ::decode() |>
googlePolylinesmap_dfr(
function(df) {
|>
df st_as_sf(coords = c("lon", "lat")) |>
st_combine() |>
st_cast("LINESTRING") |>
st_sf()
|>
}) pull(1)
}
# Get activities
<- httr::config(
activities token = strava_oauth(
app_name,
client_id,
client_secret,app_scope = "activity:read_all",
cache = TRUE)) |>
get_activity_list() |>
compile_activities()
# Map
|>
activities mutate(geom = gp2sf(map.summary_polyline)) |>
st_sf(crs = "EPSG:4326") |>
leaflet() |>
addTiles() |>
addPolylines()