Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting GPS position with R package leaflet

Tags:

r

leaflet

I'm using the R package leaftlet to create a map with some markers, but I also need to show the GPS position on the map for movile devices.

I know that this is possible in leaflet with the location method and some javascript but it seems that this method is not available in the R package: "leaflet".

What is the best way to show the GPS position in a map generated with R and leaflet?

like image 719
Alfredo Sánchez Avatar asked Aug 22 '16 10:08

Alfredo Sánchez


1 Answers

Important: Open the map in a browser not inside RStudio! And allow the request for location access!

library(leaflet)
library(leaflet.extras)

map <- leaflet() %>% addTiles()

map <- addControlGPS(map, options = gpsOptions(position = "topleft", activate = TRUE, 
                                               autoCenter = TRUE, maxZoom = 10, 
                                               setView = TRUE))
activateGPS(map)

Very cool feature, thanks for the question!

like image 181
Tonio Liebrand Avatar answered Sep 23 '22 12:09

Tonio Liebrand