Route endpoint
How to compute travel distance, time and path for a pair of origin and destination by using public transportation.
Get distance, duration, path and public transport details between an origin and a destination, based on public tranportation between those two points. This endpoint provides all the information needed to evaluate an itinerary and display it on a map. Transit API uses data provided by transit agencies (real time, timetables, average travel times) to build itineraries. In addition pedestrian mode can be proposed in itineraries to reach starting and ending points and commute between transportation modes…
Requests should be built as follows:
https://api.woosmap.com/transit/route?parameters
Required parameters
Some parameters are required to initiate a Transit Route API request. As it is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below.
https://api.woosmap.com/transit/route?destination=47.852954,2.290887&origin=49.850077,4.311124&key={PUBLIC_API_KEY}
origin
The starting point for the route. It should be supplied in the form of latitude,longitude coordinates.
destination
The ending point for the route. It should be supplied in the form of latitude,longitude coordinates.
key or private_key
Your project’s API key. This key identifies your Woosmap Project for security purposes and quota management.
(you should use key
client side and private_key
server side)
Please refer to the documentation to get an API Key if necessary.
Optional Parameters
departure_time
The date-time to base the calculation on. Valid values are date-time
with or without timezone (for example, 2019-06-24T01:23:45) or timestamp
.
If departure_time and arrival_time are not defined, the default departure_time is set to now
arrival_time
The date-time to base the calculation on. Valid values are date-time
or timestamp
.
If departure_time is set, arrival_time is ignored
The Transit API utilizes real-time, timetable, and estimated data to suggest itineraries according to availability). Real-time info provides current vehicle locations and disruptions, while timetables offer detailed schedules. Estimated travel times are provided when granular schedules are unavailable. However, we cannot guarantee coverage areas to be complete and that some transit options might be missing.
modes
Transit mode filter used to determine which modes of transit to include in the response. By default, all supported transit modes are permitted.
Supported modes: highSpeedTrain
intercityTrain
interRegionalTrain
regionalTrain
cityTrain
bus
ferry
subway
lightRail
privateBus
inclined
aerial
busRapid
monorail
flight
.
This parameter also support an exclusion list: It’s sufficient to specify each mode to exclude by prefixing it with -
.
Mixing of inclusive and exclusive transit modes is not allowed.
examples:
modes=subway,bus
: Returns only subways and busses.modes=-subway,-bus
: Returns all modes except subways and busses.
Route example
The following example requests the route between an origin to a destination:
curl -L -X GET 'https://api.woosmap.com/transit/route?origin=48.73534,2.368308&destination=48.83534,2.368308&key=YOUR_PUBLIC_API_KEY' \
-H 'Referer: http://localhost'
import requests
url = "https://api.woosmap.com/transit/route?origin=48.73534,2.368308&destination=48.83534,2.368308&key=YOUR_PUBLIC_API_KEY"
payload={}
headers = {
'Referer': 'http://localhost'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("https://api.woosmap.com/transit/route?origin=48.73534,2.368308&destination=48.83534,2.368308&key=YOUR_PUBLIC_API_KEY", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Response
Route provides a JSON response containing the following root elements:
- status contains metadata on the request. See Status Codes below.
- routes contains an array of
route
, which in turn each contain aduration
,legs
andnotice
element.
Status Codes
OK
indicates the response contains a valid result.NO_RESULTS
indicates that no route has been found between the origin and the destination.
Routes
Each routes
contains the following fields:
duration
: the duration of the route in secondsnotice
: some noticeable information about the routelegs
: information about route between your origin and your destination
Legs
Each legs
contains the following fields:
travel_mode
: the travel mode of the leg, it can bepedestrian
ortransit
.duration
: the duration of the leg in second.distance
: the distance of the leg in meters.polyline
: the polyline of the legs that can be displayed on a map if needed.overview_polyline
: The polyline of the route (encoding with the poyline5 algorithm ).start_location
: the starting location of the leg (it contains aname
, atype
and thelocation
in lat/lng ).end_location
: the ending location of the leg (it contains aname
, atype
and thelocation
in lat/lng ).transport
: all the details of the public transport if not a pedestrian leg ( Bus, Train, Number of the line, Station etc … ).attributions
: Some legal informations about the transportation company.
In certain cases, data provided by transit agencies cannot be used without displaying copyright notices to the end user. If a routing response contains this type of data, the Transit API adds operator attribution information to the route response. Operator attribution must be displayed together with a route. This requirement is part of the terms and conditions for the Woosmap Transit API.
Route endpoint server side
As for other Woosmap APIs, if you plan to use the Route endpoint of Transit API server side you must use a private_key in your requests.
.../transit/route?origin=48.836,2.237&destination=48.709,2.403&private_key=[Private APIKey]
Transit API is mostly based on the Here Public Transit API. Woosmap Transit API has been incorporated to the Woosmap platform to ease and speed-up integrations and help customers cover itinerary use cases. More details on coverage information are available here.
Example
Here is a sample of a Transit API call using our Map-JS library. It queries Route endpoint to get a distance, a duration and a path (as a polyline) of the better route between origin and destination.