# 🛤️ ⏱️Trueway Matrix API: Travel Distance and Time

### TrueWay Matrix API: Your Affordable Solution for Distance and Duration Calculation

Developer Portal : <https://api.market/store/trueway/matrix>

#### Transform Your Logistics with TrueWay Matrix API

Unlock precise and efficient route calculations with the TrueWay Matrix API, the ultimate alternative to Google Distance Matrix API. Whether you’re solving complex logistical problems, optimizing delivery routes, or enhancing search results with actual travel times, TrueWay Matrix API offers an affordable and reliable solution.

#### Key Features:

* **Comprehensive Global Coverage**: Access an extensive global road network to calculate distances and durations between multiple origins and destinations.
* **Accurate Predictions**: Utilize predictive or live traffic information to get precise travel times based on specified start times.
* **Flexible Route Options**: Customize your routes by avoiding highways, tolls, or ferries to meet your specific needs.
* **Dynamic Traffic Data**: Calculate traffic-based distance and duration matrices over specified time periods for optimal planning.
* **Scalable Requests**: Support up to 25 origins and destinations per request, providing flexibility for various applications.

#### Ideal for Multiple Applications:

* **Traveling Salesman Problem (TSP)**: Efficiently solve TSP by calculating the shortest possible route visiting multiple points.
* **Vehicle Routing Problem (VRP)**: Optimize vehicle routes to minimize travel time and distance.
* **Search Result Optimization**: Sort search results by actual travel distance or time for enhanced user experiences.
* **Arrival Time Calculation**: Determine precise arrival times based on real-time travel conditions.
* **Commute Time Comparison**: Compare travel times between different locations for better decision-making.
* **Data Clustering**: Cluster data points based on travel times and distances for advanced analytics.

#### How It Works:

The TrueWay Matrix API calculates distances and durations between specified origins and destinations. Using the CalculateDrivingDistanceMatrix request, input a list of origins and destinations to receive a matrix of optimal route distances and durations.

**Example Request:**

{% tabs %}
{% tab title="Curl" %}

```bash
{
curl -X 'GET' \
  'https://prod.api.market/api/v1/trueway/matrix/MatrixService/CalculateDrivingMatrix?origins=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&destinations=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&avoid_tolls=false&avoid_highways=false&avoid_ferries=false' \
  -H 'accept: application/json' \
  -H 'x-api-market-key: API_KEY'
}
```

{% endtab %}

{% tab title="Nodejs" %}

```bash
const fetch = require('node-fetch');

let url = 'https://prod.api.market/api/v1/trueway/matrix/MatrixService/CalculateDrivingMatrix?origins=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&destinations=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&avoid_tolls=SOME_BOOLEAN_VALUE&avoid_highways=SOME_BOOLEAN_VALUE&avoid_ferries=SOME_BOOLEAN_VALUE&start_time=SOME_STRING_VALUE';

let options = {method: 'GET', headers: {'x-api-market-key': 'SOME_STRING_VALUE'}};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));
```

{% endtab %}

{% tab title="Python" %}

```bash
import http.client

conn = http.client.HTTPSConnection("api.magicapi.dev")

headers = { 'x-api-market-key': "SOME_STRING_VALUE" }

conn.request("GET", "/api/v1/trueway/matrix/MatrixService/CalculateDrivingMatrix?origins=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&destinations=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&avoid_tolls=SOME_BOOLEAN_VALUE&avoid_highways=SOME_BOOLEAN_VALUE&avoid_ferries=SOME_BOOLEAN_VALUE&start_time=SOME_STRING_VALUE", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="Java" %}

```bash
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://prod.api.market/api/v1/trueway/matrix/MatrixService/CalculateDrivingMatrix?origins=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&destinations=40.629041%2C-74.025606%3B40.630099%2C-73.993521%3B40.644895%2C-74.013818%3B40.627177%2C-73.980853&avoid_tolls=SOME_BOOLEAN_VALUE&avoid_highways=SOME_BOOLEAN_VALUE&avoid_ferries=SOME_BOOLEAN_VALUE&start_time=SOME_STRING_VALUE")
  .get()
  .addHeader("x-api-market-key", "SOME_STRING_VALUE")
  .build();

Response response = client.newCall(request).execute();
```

{% endtab %}
{% endtabs %}

**Example Response:**

```json
{
  "distances": [
    [
      0,
      3935,
      2072,
      5420
    ],
    [
      3991,
      0,
      2602,
      1476
    ],
    [
      2660,
      2661,
      0,
      3635
    ],
    [
      5744,
      2071,
      4036,
      0
    ]
  ],
  "durations": [
    [
      0,
      830,
      500,
      1099
    ],
    [
      890,
      0,
      725,
      401
    ],
    [
      553,
      758,
      0,
      1029
    ],
    [
      1231,
      538,
      1198,
      0
    ]
  ]
}
```

In this example, the distance from the 2nd origin point to the 3rd destination point is 3646 meters, and the travel time is 1030 seconds.

#### Seamless Integration:

Integrate TrueWay Matrix API into your applications effortlessly to enhance route planning, logistics optimization, and travel-time analysis. With our affordable pricing, you can perform multiple API calls without breaking the bank, making TrueWay a cost-effective choice compared to Google Distance Matrix API.

#### Get Started Now!

Optimize your routes, improve efficiency, and make data-driven decisions with TrueWay Matrix API, the most affordable distance matrix API on the market.

Enhance your API mapping solutions and see why TrueWay Routing API is the smart choice for your business needs.\
\
Developer Portal : <https://api.market/store/trueway/matrix>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.api.market/api-product-docs/trueway/trueway-matrix-api-travel-distance-and-time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
