Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Server api

DennisOSRM edited this page Feb 17, 2012 · 6 revisions

OSRM Server API

OSRM (partially) implements http 1.1 and serves queries much like normal web servers do.

Available Services

OSRM features three services currenty. These are:

  1. Location of a nearest node of the road network to a given coordinate (locate).
  2. Location of a nearest point on any street segment of the road network for a given coordinate. (nearest)
  3. Computation of a shortest path on the road network between two coordinates given an ordered list of via points (viaroute).

Anatomy of the query string

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&param2=value&...&paramX=value

Location Queries

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.

Locating a Node

A nearest node point is queried by sending a request formatted as follows:

http://server:5000/locate?_lat_&_lon_

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:

http://server:5000/locate?52.555485441735&13.342227642887

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)"
}

Nearest point on a street

A nearest point on a street segment is queried by sending a request formatted as follows:

http://server:5000/nearest?_lat_&_lon_

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:

http://server:5000/locate?52.555485441735&13.342227642887

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)"
}

Additional parameters (JSONP)

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.

Requesting routes

Basic point to point queries are requested like this

http://server:5000/viaroute?start=52.555485441735,13.342227642887&dest=52.549170669465,13.349179928653

To be continued

Clone this wiki locally