Project OSRM
Open Source Routing Machine
Project OSRM API
- HTTP API
- Library API
- NodeJS API
HTTP API
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
Location of the server.
Example: 10.15.162.7:5000
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
Service |
Description |
nearest |
returns the nearest street segment for a given coordinate |
route |
shortest path between given coordinates |
table |
computes duration tables for given coordinates |
match |
matches given coordinates to the road network |
trip |
compute the shortest round trip between given coordinates |
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
- Version of the protocol implemented by the service.
- Default version is 1 (eg. v1)
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
- Profiles mode, including car, bicycle and foot. (eg. driving, cycling or walking)
- Profile configuration files have a 'lua' extension, and are found under the 'profiles' subdirectory.
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
- String of format {longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...] or polyline({polyline}).
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
- Only json is supported at the moment.
- This parameter is *optional and defaults to json.
Request
http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option=value
- General options can be used with all services.
- Refer to Additional options of each service for more options.
Option |
Values |
Description |
bearings |
{bearing};{bearing}[;{bearing} ...] |
Limits the search to segments with given bearing in degrees towards true north in clockwise direction. |
radiuses |
{radius};{radius}[;{radius} ...] |
Limits the search to given radius in meters. |
hints |
{hint};{hint}[;{hint} ...] |
Hint to derive position in street network. |
Response
{ "code": {code}, "message": {message} }
Code |
Description |
Ok |
Request could be processed as expected. |
InvalidUrl |
URL string is invalid. |
InvalidService |
Service name is invalid. |
InvalidVersion |
Version is not found. |
InvalidOptions |
Options are invalid. |
NoSegment |
One of the supplied input coordinates could not snap to street. |
TooBig |
The request size violates one of the service specific request size restrictions. |
Response
{ "code": {code}, "message": {message} }
*optional human-readable error message. (code Ok usually don’t come with any message)
Services
- Nearest
- Route
- Table
- Match
- Trip
Nearest
Snaps a coordinate to the street network and returns the nearest and matches
Nearest
http://{server}/nearest/v1/{profile}/{coordinates}.json?{option}=value
single {longitude},{latitude}
number
code - if the request was successful: Ok ,otherwise see the service dependent and general status codes above.
waypoints - array of Waypoint objects sorted by distance to the input coordinate. Each object has at least the following additional properties:
- distance - Distance in meters to the supplied input coordinate.
Response:
Eg.
Route
Get the shortest path between given coordinates
Route
http://{server}/route/v1/{profile}/{coordinates}?{option}=value&{option}..
alternatives |
steps |
annotations |
geometries |
overview |
continue_straight |
code - if the request was successful: Ok ,otherwise see the service dependent and general status codes.
waypoints - Array of Waypoint objects representing all waypoints in order
routes - An array of Route objects, ordered by descending recommendation rank.
Response:
Eg.
Table
Computes duration tables for given coordinates
Table
http://{server}/table/v1/{profile}/{coordinates}?{option}=value&{option}..
code - if the request was successful: Ok ,otherwise see the service dependent and general status codes.
durations - array of arrays that stores the matrix in row-major order. Values are given in seconds.
sources - array of Waypoint objects describing all sources in order
destinations - array of Waypoint objects describing all destinations in order
Response:
Eg.
sources |
destinations |
Match
Map matching matches given GPS points to the road network in the most plausible way
Match
http://{server}/match/v1/{profile}/{coordinates}?{option}=value&{option}..
code - if the request was successful Ok otherwise see the service dependent and general status codes.
tracepoints - Array of Ẁaypoint objects representing all points of the trace in order. If the trace point was ommited by map matching because it is an outlier, the entry will be null. Each Waypoint object has the following additional properties:
- matchings_index - Index to the Route object in matchings the sub-trace was matched to.
- waypoint_index - Index of the waypoint inside the matched route.
matchings - An array of Route objects that assemble the trace. Each Route object has the following additional properties:
- confidence - Confidence of the matching. float value between 0 and 1. 1 is very confident that the matching is correct.
Response:
Eg.
steps |
geometries |
annotations |
overview |
timestamps |
radiuses |
Trip
Compute the shortest round trip between given coordinates
Trip
http://{server}/trip/v1/{profile}/{coordinates}?{option}=value&{option}..
code - if the request was successful Ok otherwise see the service dependent and general status codes.
waypoints - Array of Waypoint objects representing all waypoints in input order. Each Waypoint object has the following additional properties:
- trips_index - Index to trips of the sub-trip the point was matched to.
- waypoint_index - Index of the point in the trip.
trips - An array of Route objects that assemble the trace.
Response:
Eg.
steps |
annotations |
geometries |
overview |
RouteStep
Consists of a maneuver such as a turn or merge, followed by a distance of travel along a single way to the subsequent step.
- distance: The distance of travel from the maneuver to the subsequent step, in float meters.
- duration: The estimated travel time, in float number of seconds.
-
geometry: The unsimplified geometry of the route segment, depending on the geometries parameter.
-
name: The name of the way along which travel proceeds.
- pronunciation: The pronunciation hint of the way name. Will be undefined if there is no pronunciation hit.
- destinations: The destinations of the way. Will be undefined if there are no destinations.
- mode: A string signifying the mode of transportation.
- maneuver: A StepManeuver object representing the maneuver.
- intersections: A list of Intersections that are passed along the segment, the very first belonging to the StepManeuver
RouteStep Properties
Example
{"intersections":
[{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[0,90,180,270],"location":[101.662552,3.115442]},
{"out":0,"in":1,"entry":[true,false,false],"bearings":[0,180,210],"location":[101.662549,3.116177]},
{"out":0,"in":2,"entry":[true,false,false],"bearings":[30,120,210],"location":[101.662865,3.1173]},
{"out":1,"in":2,"entry":[true,true,false],"bearings":[15,45,225],"location":[101.663481,3.118112]},
{"out":0,"in":1,"entry":[true,false,false],"bearings":[90,270,330],"location":[101.664188,3.118541]},
{"out":1,"in":2,"entry":[true,true,false],"bearings":[75,120,285],"location":[101.665164,3.11837]}],
"geometry":"on_R}}nkRsC?w@?iAQ}Am@oCkBQMw@u@O]K[A]B{@\\eCBI",
"maneuver":
{"bearing_after":360,"bearing_before":357,
"location":[101.662552,3.115442],
"modifier":"straight","type":"turn"},
"mode":"driving",
"duration":37.6,
"name":"Jalan Pantai Baru",
"distance":537.6},
Maneuver Type
turn: a basic turn into direction of the modifier
new name: no turn is taken/possible, but the road name changes. The road can take a turn itself, following modifier.
depart: indicates the departure of the leg
arrive: indicates the destination of the leg
merge: merge onto a street
on ramp: take a ramp to enter a highway (direction given my modifier)
off ramp: take a ramp to exit a highway (direction given my modifier)
fork: take the left/right side at a fork depending on modifier
end of road: road ends in a T intersection turn in direction of modifier
continue: Turn in direction of modifier to stay on the same road
roundabout: traverse roundabout, has additional field exit with NR if the roundabout is left
rotary: a larger version of a roundabout, can offer rotary_name in addition to the exit parameter.
roundabout turn: Describes a turn at a small roundabout that should be treated as normal turn. The modifier indicates the turn direciton. Example instruction: At the roundabout turn left.
notification: not an actual turn but a change in the driving conditions. For example the travel mode. If the road takes a turn itself, the modifier describes the direction
Maneuver Modifier
uturn: indicates reversal of direction
sharp right: a sharp right turn
right: a normal turn to the right
slight right: a slight turn to the right
straight: no relevant change in direction
slight left: a slight turn to the left
left: a normal turn to the left
sharp left: a sharp turn to the left
Intersections
- location: A [longitude, latitude] pair describing the location of the turn.
- bearings: A list of bearing values (e.g. [0,90,180,270]) that are available at the intersection. The bearings describe all available roads at the intersection.
- entry: A list of entry flags, corresponding in a 1:1 relationship to the bearings. A value of true indicates that the respective road could be entered on a valid route. false indicates that the turn onto the respective road would violate a restriction.
- in: index into bearings/entry array. Used to calculate the bearing just before the turn. Namely, the clockwise angle from true north to the direction of travel immediately before the maneuver/passing the intersection. Bearings are given relative to the intersection. To get the bearing in the direction of driving, the bearing has to be rotated by a value of 180. The value is not supplied for depart maneuvers.
- out: index into the bearings/entry array. Used to extract the bearing just after the turn. Namely, The clockwise angle from true north to the direction of travel immediately after the maneuver/passing the intersection. The value is not supplied for arrive maneuvers.
{"intersections": [{"out":0,"in":2,"entry":[true,true,false,false],"bearings":[0,90,180,270],"location":[101.662552,3.115442]},
Data Format
only supports plaintext ASCII grid sources (.asc)
Profiles
Data must be tagged along with profiles (.lua)
Quiz
A salesman has 3 places to go by car and want to know where he needs to go first.
Please select the suitable service to use.
Trip
Nearest
Table
A
B
C
Match
D
Project OSRM
By Annuar Faiz
Project OSRM
- 880