Learn R Programming

osrm (version 1.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(xo, yo, xd, yd)

Arguments

xo
longitude of the origine point.
yo
latitude of the origine point.
xd
longitude of the destination point.
yd
latitude of the destination point.

Value

  • A named numeric vector is return. 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(xo = com[1,"lon"], yo = com[1,"lat"],
                      xd = com[15,"lon"], yd = com[15,"lat"])
# 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