Pairs Directions API
Try Routing API to plot car, truck, bicycle, or pedestrian routes through one service.
Pairs Directions API allows you to build multiple routes in a single call. For each route you can get its length, travel time, and geometry.
Each route can only consist of two points: departure and arrival.
Pairs Directions API supports the following types of routes:
- car routes
- car routes including public transport lanes (taxi routes)
- pedestrian routes
- bicycle routes
Getting an access key
Usage of this API requires an API key. To obtain the key:
- Sign in to the Platform Manager.
- Create a demo key (if you have not used Urbi products before) or request a production key: follow the link to contact a manager on the API Keys tab.
In the Platform Manager, you can also:
- See information on your current keys: which services are enabled, which limit is set for each, when a key will be deactivated, and more.
- Set restrictions for a key by HTTP headers or by IP and subnet.
- Check the statistics of request distribution for each key.
Request example
To get route information, send a POST request to the /get_pairs/1.0/{routing_type}
endpoint, where routing_type
is the required type of route:
car
- car routetaxi
- car route that includes public transport lanespedestrian
- pedestrian routebicycle
- bicycle route
Specify your API key as the key
parameter in the query string.
https://routing.api.2gis.com/get_pairs/1.0/car?key=API_KEY
Coordinates for the route and other parameters must be sent as a JSON string in the request body.
In the simplest case, the JSON object may contain only three fields:
points
- an array of routes. Each object in the array must contain four fields: the latitude and longitude of the point of departure (lat1
andlon1
) and the latitude and longitude of the point of arrival (lat2
andlon2
).type
- route type (the optimal route taking traffic into account or just the shortest route between the points).output
- output format (simplified or full).
curl --request POST \
--url 'https://routing.api.2gis.com/get_pairs/1.0/car?key=API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"points": [
{
"lon1": 82.933328,
"lat1": 55.102268,
"lon2": 82.958722,
"lat2": 55.032594
}
],
"type": "jam",
"output": "simple"
}'
You can use additional parameters to exclude specific areas and road types from the route. For more information on route types and additional parameters, see Directions API.
Response example
The request will return information about each route, including the route length in meters (distance
) and travel time in seconds (duration
). If you specify the full output format ("output": "full"
), the request will also return the full geometry of the route.
[
{
"lon1": 82.933328,
"lat1": 55.102268,
"lon2": 82.958722,
"lat2": 55.032594,
"distance": 11146,
"duration": 1509,
"status": "OK"
}
]