Source: https://developers.woosmap.com/products/transit-api/route-endpoint/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Route endpoint



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:

```plaintext
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.

```plaintext
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](/api-reference/authentication/) 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:

```shell
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'
```

```python
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)
```

```javascript
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 a `duration`, `legs` and `notice` 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 seconds
- `notice`: some noticeable information about the route
- `legs`: 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 be `pedestrian` or `transit`.
- `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 (encoded with the [polyline algorithm](/products/map-api/concepts/polyline-encoding/)).
- `start_location`: the starting location of the leg (it contains a `name`, a `type` and the `location` in lat/lng ).
- `end_location`: the ending location of the leg (it contains a `name`, a `type` and the `location` 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.

```plaintext
.../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](https://www.here.com/docs/bundle/public-transit-api-developer-guide/page/README.html). 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](https://www.here.com/docs/bundle/public-transit-api-developer-guide/page/coverage.html).

## Example

Here is a sample of a Transit API call using our [Map-JS library](/products/map-api/get-started/). It queries Route endpoint to get a distance, a duration and a path (as a polyline) of the better route between origin and destination.

https://demo.woosmap.com/js-samples/samples/transit-advanced/app/dist/
[](https://demo.woosmap.com/js-samples/samples/transit-advanced/highlight/highlight.html "Open in new tab with highlighted code")
Try sample 

- [CodeSandbox](https://codesandbox.io/p/devbox/github/woosmap/js-samples/tree/master/dist/samples/transit-advanced/app?file=index.ts)
- [JsFiddle](https://jsfiddle.net/gh/get/library/pure/woosmap/js-samples/tree/master/dist/samples/transit-advanced/jsfiddle)
- [Clone on Github](https://github.com/Woosmap/js-samples/tree/sample/transit-advanced)
