---
title: "Direction API"
description: "The best driving route between two points, with distance, travel time and the full path."
canonical_url: "http://0.0.0.0:6006/direction"
markdown_url: "http://0.0.0.0:6006/direction.md"
last_updated: "2026-11-17"
x_farming_labs_generated_preamble: true
---

# Direction API
URL: /direction
LLM index: /llms.txt
Description: The best driving route between two points, with distance, travel time and the full path.

# Direction API

The Direction API returns the best driving route from an origin to a destination, optionally through stops along the way. You get the travel time, the total distance and the route as a list of coordinates you can draw on a map, plus other possible routes if you ask for them.

## When to use it

<Cards>
  <Card icon={<PaperPlaneIcon />} title="Navigation">
    Show the route and an arrival estimate in your app or website.
  </Card>
  <Card icon={<ClockIcon />} title="Arrival times">
    Tell a customer when their driver or delivery will arrive.
  </Card>
  <Card icon={<DrawingPinIcon />} title="Multi-stop trips">
    Route through up to 10 waypoints in a fixed order. To have the order chosen for you, use the [Route Optimization API](/route-optimization).
  </Card>
  <Card icon={<GlobeIcon />} title="Interactive maps">
    Draw routes for tours, games or teaching tools.
  </Card>
  <Card icon={<ActivityLogIcon />} title="Traffic research">
    Compare travel times between the same points over time.
  </Card>
</Cards>

## Request

```bash
GET https://mapapi.gebeta.app/api/route/direction/?origin={lat,lng}&destination={lat,lng}&apiKey={your-api-key}
```

| Parameter     | Type     | Required | Description                                                                                       |
| ------------- | -------- | -------- | ------------------------------------------------------------------------------------------------- |
| `origin`      | `string` | Yes      | Where the route starts, as `{lat,lng}`.                                                           |
| `destination` | `string` | Yes      | Where the route ends, as `{lat,lng}`.                                                             |
| `apiKey`      | `string` | Yes      | Your Gebeta Maps API key.                                                                         |
| `waypoints`   | `string` | No       | Stops to pass through in order, as `[{lat,lng},{lat,lng},…]`. Up to 10.                            |
| `alternative` | `string` | No       | Set to `t` to also get other possible routes, in `alternates`.                                    |

## Example

<Tabs items={["cURL", "JavaScript", "Python", "Go", "PHP", "Ruby", "Rust", "Dart"]}>
<Tab value="cURL">

```bash
curl "https://mapapi.gebeta.app/api/route/direction/?origin={8.989022,38.79036}&destination={9.03045,38.76530}&apiKey={your-api-key}"
```

</Tab>
<Tab value="JavaScript">

```javascript
const origin = "{8.989022,38.79036}";
const destination = "{9.03045,38.76530}";
const url = `https://mapapi.gebeta.app/api/route/direction/?origin=${origin}&destination=${destination}&apiKey=${apiKey}`;

const response = await fetch(url);
const route = await response.json();
console.log(route.totalDistance, route.timetaken);
```

</Tab>
<Tab value="Python">

```python
import requests

origin = "{8.989022,38.79036}"
destination = "{9.03045,38.76530}"
url = f"https://mapapi.gebeta.app/api/route/direction/?origin={origin}&destination={destination}&apiKey={api_key}"

route = requests.get(url).json()
print(route["totalDistance"], route["timetaken"])
```

</Tab>
<Tab value="Go">

```go
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

func main() {
	apiKey := "{your-api-key}"
	origin := "{8.989022,38.79036}"
	destination := "{9.03045,38.76530}"
	url := fmt.Sprintf("https://mapapi.gebeta.app/api/route/direction/?origin=%s&destination=%s&apiKey=%s", origin, destination, apiKey)

	resp, err := http.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var route map[string]any
	json.NewDecoder(resp.Body).Decode(&route)
	fmt.Println(route["totalDistance"], route["timetaken"])
}
```

</Tab>
<Tab value="PHP">

```php
<?php
$apiKey = "{your-api-key}";
$origin = "{8.989022,38.79036}";
$destination = "{9.03045,38.76530}";
$url = "https://mapapi.gebeta.app/api/route/direction/?origin=$origin&destination=$destination&apiKey=$apiKey";

$route = json_decode(file_get_contents($url), true);
echo $route["totalDistance"], " ", $route["timetaken"];
```

</Tab>
<Tab value="Ruby">

```ruby
require "net/http"
require "json"

api_key = "{your-api-key}"
origin = "{8.989022,38.79036}"
destination = "{9.03045,38.76530}"
url = URI("https://mapapi.gebeta.app/api/route/direction/?origin=#{origin}&destination=#{destination}&apiKey=#{api_key}")

route = JSON.parse(Net::HTTP.get(url))
puts route["totalDistance"], route["timetaken"]
```

</Tab>
<Tab value="Rust">

```rust
use serde_json::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = "{your-api-key}";
    let origin = "{8.989022,38.79036}";
    let destination = "{9.03045,38.76530}";
    let url = format!(
        "https://mapapi.gebeta.app/api/route/direction/?origin={origin}&destination={destination}&apiKey={api_key}"
    );

    let route: Value = reqwest::blocking::get(url)?.json()?;
    println!("{} {}", route["totalDistance"], route["timetaken"]);
    Ok(())
}
```

</Tab>
<Tab value="Dart">

```dart
import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> main() async {
  const apiKey = '{your-api-key}';
  const origin = '{8.989022,38.79036}';
  const destination = '{9.03045,38.76530}';
  final url = Uri.parse(
    'https://mapapi.gebeta.app/api/route/direction/?origin=$origin&destination=$destination&apiKey=$apiKey',
  );

  final route = jsonDecode((await http.get(url)).body);
  print('${route['totalDistance']} ${route['timetaken']}');
}
```

</Tab>
</Tabs>

To route through stops, add `waypoints`:

```bash
curl "https://mapapi.gebeta.app/api/route/direction/?origin={8.989022,38.79036}&destination={9.03045,38.76530}&waypoints=[{9.0102,38.7612},{9.0201,38.7701}]&apiKey={your-api-key}"
```

## Response

```json
{
  "msg": "Ok",
  "timetaken": 1275.631,
  "totalDistance": 8895,
  "direction": [
    [9.055978, 38.704943],
    [9.056214, 38.704691]
  ]
}
```

| Field           | Description                                                                                          |
| --------------- | ---------------------------------------------------------------------------------------------------- |
| `msg`           | `Ok` when a route was found.                                                                         |
| `timetaken`     | Travel time for the whole route, in seconds.                                                         |
| `totalDistance` | Length of the whole route, in meters.                                                                |
| `direction`     | The route as `[lat, lng]` points, in order. Draw them as a line on a map. A real response has hundreds of points; this example shows the first two. |

### Alternative routes

With `alternative=t`, the response also has `alternates`: other routes between the same points, each with its own time, distance and line.

```json
{
  "msg": "Ok",
  "timetaken": 1275.631,
  "totalDistance": 8895,
  "direction": [[9.055978, 38.704943]],
  "alternates": [
    { "timetaken": 1182.037, "totalDistance": 8425, "direction": [[9.055978, 38.704943]] },
    { "timetaken": 1404.338, "totalDistance": 10585, "direction": [[9.055978, 38.704943]] }
  ]
}
```

An alternate can be quicker than the main route, as the first one is here, so compare `timetaken` if you want the fastest.

## Errors

| Status | Message                          | What to do                                                           |
| ------ | -------------------------------- | -------------------------------------------------------------------- |
| `401`  | `Not Authorized - No Token`      | Add your API key as the `apiKey` parameter.                          |
| `401`  | `Not Authorized - Invalid Token` | The key is wrong or expired. Copy a current key from your dashboard. |
| `404`  | `NoRoute`                        | There's no road between the points. Check they're reachable by car.  |
| `422`  | `InvalidInput`                   | Check that `origin`, `destination` and `waypoints` use `{lat,lng}`.  |

Errors come back in this shape:

```json
{
  "error": {
    "additional": null,
    "code": "A_ERR00004",
    "message": "Invalid access token!",
    "status": 401
  }
}
```

## Limits

- **Rate:** 50 requests per second per API key. Requests above that are rejected, so throttle them or spread traffic across keys for different apps.
- **Waypoints:** Up to 10 per request.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
