Description Usage Arguments Value Examples
Calculate shortest route visiting every destination before returning home.
1 2 |
fromaddress |
is an adress type: roadname+housenumber+postalcode |
fromcoord |
is a coordinate type: latitude, longtitude |
tocoords |
is a coordinate type: latitude, longtitude. Must be a data frame with a lat and lng column |
metric |
is a choice of cost metric for optimal route. Either "time" (default) or "distance" |
zvalue |
is the zoom level for polyline. Integer in the range 1 to 19. Default: 18 |
Returns a list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Create data frame with coordinates
coords <- dplyr::data_frame(
lat = c(55.70873874051673, 55.68745586048921, 55.67274455523506,
55.70390273988158, 55.62799595426723, 55.7425739894847),
lng = c(12.581062316894531, 12.496261596679688, 12.48870849609375,
12.363052368164062, 12.55256652832031, 12.454376220703125))
# TSP optimized for shortest travelling time:
tsp(fromcoord = "55.6896,12.55792", tocoords = coords, metric = "time")
# TSP optimized for shortest travelling distance:
tsp(fromcoord = "55.6896,12.55792", tocoords = coords, metric = "distance")
# Decode the compressed polyline
mytsp <- tsp(fromcoord = "55.6896,12.55792", tocoords = coords, metric = "distance")
decodepolyline(mytsp$steps[[1]]$route_geometry)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.