1

I am able to retrive a Direction map with the below Rscript, but I am unable to find function for making it Interactive.

longitude <- c( 77.605855,77.606800,77.596843,77.575793 )
latitude <- c(12.956580,12.966157, 12.964777,12.964473)
d <- as.data.frame(cbind(longitude,latitude))
map <- get_googlemap(center = c(lon = 77.605855, lat = 12.956580), zoom = 14,
          size = c(500, 500), scale = 2,maptype = c("roadmap"),markers = d, path = d)

Below are the functionalities that I need to have in my map.
1. Interactive Zoom.
2. Auto Center so that all the markers are visible.
3. OnClick on the marker I would like to show title -say for Eg. "This is Your Car".

Tareva
  • 230
  • 1
  • 13
  • You might be interested in this [post](https://stackoverflow.com/questions/32164452/dynamic-plotting-using-ggmap-package-in-r) – Prem Aug 04 '17 at 11:24
  • See my [answer here](https://stackoverflow.com/a/42034607/5977215) – SymbolixAU Aug 04 '17 at 12:55
  • @SymbolixAU Thanks for the Solution, but My Issue is I dont have `Origin` and `destination`, all I have is a set of `Lat & Lon` where the Vehicle has traveled and I need to plot the directions accordingly. What would be the work around for replacing `Origin & Destination ` with `Lat & Lon` Kindly help. – Tareva Aug 07 '17 at 04:39
  • Take a look at some of the [`googleway` examples](https://github.com/SymbolixAU/googleway/blob/master/vignettes/googleway-vignette.Rmd#markers) and the [`leaflet` examples](http://rstudio.github.io/leaflet/), both offer interactive maps where you can plot markers and routes, and have the markers with a 'onClick' event to show a pop-up – SymbolixAU Aug 07 '17 at 05:16
  • @SymbolixAU Thanks!!! Those examples you referred helped me to some extent. Thanks again. – Tareva Aug 07 '17 at 07:07

1 Answers1

1

The documentation leaflet referred by @SymbolixAU at the comments helped me to arrive at the solution, below is my code to address my requirements mentioned in the question.

library(leaflet)

longitute <-c(77.605855,77.606800,77.596843,77.596747,77.596296,77.595738,77.594944 )
latitude <- c(12.956580,12.966157, 12.964777,12.964323,12.963570,12.962964, 12.962399)
d <- as.data.frame(cbind(longitute,latitude))   
m <- leaflet() %>%
addTiles() %>%  # Add default OpenStreetMap map tiles
addMarkers(lng=d$longitute, lat=d$latitude, popup="New Point",)
m<- addPolylines(m , lng = d$longitute, lat = d$latitude)
m

So this is my Output.
enter image description here

Tareva
  • 230
  • 1
  • 13