I was looking into this repo, where a blue dot is added to your leaflet map, that if you open it on a phone, it follows you as you walk, similar to a google maps option, as shown in this demo.
Usually in R and using Rmd, I would have this code so that I can know where I am on the map:
title: "Test map" output: html_document
knitr::opts_chunk$set(echo = TRUE)
library(leaflet)
Old map.locate option
I usually made this maps for the field
leaflet() %>%
addTiles() %>%
setView(-71.0382679, 42.3489054, zoom = 18) %>%
addEasyButton(easyButton(
icon="fa-crosshairs", title="Locate Me",
onClick=JS("function(btn, map){ map.locate({setView: true, enableHighAccuracy: true }); }")))
That works great for finding your location, but it does not generate a marker where you are, and more importantly, it does not follow you around, you can see an example of that here
Trying to incorporate control.locate
So my first try was just to change locate for control.locate, but that did not work.
leaflet() %>%
addTiles() %>%
setView(-71.0382679, 42.3489054, zoom = 18) %>%
addEasyButton(easyButton(
icon="fa-crosshairs", title="Follow Me",
onClick=JS("function(btn, map){ map.control.locate()}")))
I am still thinking of other options, but any help would be welcome, here is the full rmd in github