---
title: geo.totalDistance() function
description: geo.totalDistance() calculates the total distance covered by subsequent points in each input table.
url: https://docs.influxdata.com/flux/v0/stdlib/experimental/geo/totaldistance/
estimated_tokens: 1895
product: Flux
version: v0
---

# geo.totalDistance() function

-   Flux 0.192.0+
-   View InfluxDB support

`geo.totalDistance()` is experimental and [subject to change at any time](/flux/v0/stdlib/experimental/#experimental-packages-are-subject-to-change).

`geo.totalDistance()` calculates the total distance covered by subsequent points in each input table.

Each row must contain `lat` (latitude) and `lon` (longitude) columns that represent the geographic coordinates of the point. Row sort order determines the order in which distance between points is calculated. Use the `geo.units` option to specify the unit of distance to return (default is km).

##### Function type signature

```js
(<-tables: stream[{B with lon: float, lat: float}], ?outputColumn: A) => stream[C] where C: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### outputColumn

Total distance output column. Default is `_value`.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

-   [Return the total distance travelled per input table](#return-the-total-distance-travelled-per-input-table)
-   [Return the total distance travelled in miles](#return-the-total-distance-travelled-in-miles)

### Return the total distance travelled per input table

```js
import "experimental/geo"

data
    |> geo.totalDistance()
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| *id | _time | lat | lon |
| --- | --- | --- | --- |
| ABC1 | 2022-01-01T00:00:00Z | 85.1 | 42.2 |
| ABC1 | 2022-01-01T01:00:00Z | 71.3 | 50.8 |
| ABC1 | 2022-01-01T02:00:00Z | 63.1 | 62.3 |
| ABC1 | 2022-01-01T03:00:00Z | 50.6 | 74.9 |

| *id | _time | lat | lon |
| --- | --- | --- | --- |
| DEF2 | 2022-01-01T00:00:00Z | -10.8 | -12.2 |
| DEF2 | 2022-01-01T01:00:00Z | -16.3 | -0.8 |
| DEF2 | 2022-01-01T02:00:00Z | -23.2 | 12.3 |
| DEF2 | 2022-01-01T03:00:00Z | -30.4 | 24.9 |

#### Output data

| *id | _value |
| --- | --- |
| ABC1 | 4157.144498077607 |

| *id | _value |
| --- | --- |
| DEF2 | 4428.129653320098 |

### Return the total distance travelled in miles

```js
import "experimental/geo"

option geo.units = {distance: "mile"}

data
    |> geo.totalDistance()
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| *id | _time | lat | lon |
| --- | --- | --- | --- |
| ABC1 | 2022-01-01T00:00:00Z | 85.1 | 42.2 |
| ABC1 | 2022-01-01T01:00:00Z | 71.3 | 50.8 |
| ABC1 | 2022-01-01T02:00:00Z | 63.1 | 62.3 |
| ABC1 | 2022-01-01T03:00:00Z | 50.6 | 74.9 |

| *id | _time | lat | lon |
| --- | --- | --- | --- |
| DEF2 | 2022-01-01T00:00:00Z | -10.8 | -12.2 |
| DEF2 | 2022-01-01T01:00:00Z | -16.3 | -0.8 |
| DEF2 | 2022-01-01T02:00:00Z | -23.2 | 12.3 |
| DEF2 | 2022-01-01T03:00:00Z | -30.4 | 24.9 |

#### Output data

| *id | _value |
| --- | --- |
| ABC1 | 2583.129833073356 |

| *id | _value |
| --- | --- |
| DEF2 | 2751.5122020650015 |

[transformations](/flux/v0/tags/transformations/) [geotemporal](/flux/v0/tags/geotemporal/) [aggregates](/flux/v0/tags/aggregates/)
