> ## Documentation Index
> Fetch the complete documentation index at: https://docs.farmtrace.co.za/llms.txt
> Use this file to discover all available pages before exploring further.

# Location functions

> Create coordinates, read latitude or longitude, and calculate distance.

Location values contain a latitude and longitude pair. Device-specific coordinates are covered under [special functions](/reference/special).

## `Distance`

Calculates the surface distance between two locations.

* **Syntax:** `Distance(first, second[, unit])`
* **Requires:** two Location values. The optional unit is `"m"`, `"km"`, or `"mi"`; metres are used by default.
* **Returns:** Numeric distance in the selected unit.
* **Best for:** service radiuses, route triage, and proximity checks.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Distance([Current Location], [Site Location], "km")
```

## `Latitude`

Returns the latitude component of a location.

* **Syntax:** `Latitude(location)`
* **Requires:** a Location value.
* **Returns:** Numeric latitude.
* **Best for:** mapping integrations and coordinate exports.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Latitude([Site Location])
```

## `Longitude`

Returns the longitude component of a location.

* **Syntax:** `Longitude(location)`
* **Requires:** a Location value.
* **Returns:** Numeric longitude.
* **Best for:** mapping integrations and coordinate exports.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Longitude([Site Location])
```

## `ToLocation`

Creates a location from coordinate text or from separate latitude and longitude numbers.

* **Syntax:** `ToLocation(text)` or `ToLocation(latitude, longitude)`
* **Requires:** coordinate text, or a latitude from `-90` to `90` and longitude from `-180` to `180`.
* **Returns:** Location.
* **Best for:** imported GPS data and calculated coordinates.

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
ToLocation("-33.9249, 18.4241")
ToLocation(-33.9249, 18.4241)
```

<Tip>
  Keep coordinates as a Location value while calculating. Extract latitude or longitude only at an integration boundary.
</Tip>
