-
Notifications
You must be signed in to change notification settings - Fork 0
Server api
OSRM (partially) implements http 1.1 and serves queries much like normal web servers do.
OSRM features three services currenty. These are:
- Location of a nearest node of the road network to a given coordinate (locate).
- Location of a nearest point on any street segment of the road network for a given coordinate. (nearest)
- Computation of a shortest path on the road network between two coordinates given an ordered list of via points (viaroute).
The general layout of a query is much like query strings for http. Once OSRM is started it listens for incoming connections. Let's assume a server called server listens on port 5000.
The any service can be queried through
http://server:5000/_service_?param1=value¶m2=value&...¶mX=value
Locating points on the road network can be done either by using the command nearest or locate. If you are unsure whether to use the neareast or the locate service, then rule of thumb says you should use nearest.
The nearest neighbor locationing relies on an external memory data structure on the harddrive. To keep the number of disk accesses low, it searches only a limited area around the input coordinate.
A nearest node point is queried by sending a request formatted as follows:
where lat and lon are latitude and longitude of the respective coordinate. For example, the following query will ask for the closest node to a certain location in Berlin, Germany:
The answer that is returned looks like this:
{
"version": 0.3,
"status": 0,
"result": [
52.54847,
13.3556
],
"transactionId": "OSRM Routing Engine JSON Locate (v0.3)"
}A nearest point on a street segment is queried by sending a request formatted as follows:
where lat and lon are latitude and longitude of the respective coordinate. For example, the following query will ask for a closest point on any street segment to a certain location in Berlin, Germany:
The answer that is returned looks like this:
{
"version": 0.3,
"status": 0,
"result": [
52.55567,
13.34252
],
"transactionId": "OSRM Routing Engine JSON Nearest (v0.3)"
}Using the syntax above, the answer comes formatted as JSON, which can be further processed by many programming languages without much futher ado. The output can also be formatted as JSONP, e.g.
http://server:5000/nearest?52.555485441735&13.342227642887&jsonp=function
returns the JSON output wrapped by function(), which is easily processable by Javascript:
function({"version":0.3,"status":0,"result":[52.55567, 13.34252],"transactionId": "OSRM Routing Engine JSON Nearest (v0.3)"})
Note that the jsonp parameter works for both nearest and locate.
Basic point to point queries are requested like this
To be continued