Learn R Programming

osrm (version 2.0.0)

osrmViaroute: Get Travel Time and Travel Distance Between Two Points

Description

Build and send an OSRM API query to get travel time and travel distance between two points. This function interface the viaroute OSRM service.

Usage

osrmViaroute(src, dst)

Arguments

src
latitude and longitude of the origine point (numeric vector of length 2)
dst
latitude and longitude of the destination point (numeric vector of length 2).

Value

  • A named numeric vector is returned. It contains travel time (in minutes) and travel distance (in kilometers).

See Also

osrmViarouteGeom

Examples

Run this code
# Load data
data("com")
# Time and Distance between 2 points
route <- osrmViaroute(src = com[1,c("lat","lon")],
                      dst = com[15,c("lat","lon")] )
# Time travel distance (min)
route[1]
# Travel distance (km)
route[2]
# Mean Speed (km/h)
route[2]/(route[1]/60)

Run the code above in your browser using DataLab