# @spatial/distance

> turf distance module

Latest version **2.0.0** (published 2020-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @spatial/distance
pnpm add @spatial/distance
yarn add @spatial/distance
bun add @spatial/distance
```

## Health

**Score 50/100 (C)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score; popular repo.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-09-18 |
| First published | 2019-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10462 |
| Author | Turf Authors |
| Maintainers | normanbreau, tpnormanbreau |
| Keywords | turf, distance, miles, km |

## Links

- npm: https://www.npmjs.com/package/@spatial/distance
- Repository: https://github.com/Turfjs/turf
- Issues: https://github.com/Turfjs/turf/issues
- npm.io page: https://npm.io/package/@spatial/distance

## Dependencies (2)

- [@spatial/helpers](https://npm.io/package/@spatial/helpers.md) ^2.0.0
- [@spatial/invariant](https://npm.io/package/@spatial/invariant.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2020-09-18
- 1.0.5 — 2019-08-09
- 1.0.4 — 2019-05-21
- 1.0.3 — 2019-05-21

## README

# @spatial/distance

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## distance

Calculates the distance between two [points][1] in degrees, radians,
miles, or kilometers. This uses the
[Haversine formula][2]
to account for global curvature.

### Parameters

-   `from` **[Coord][3]** origin point
-   `to` **[Coord][3]** destination point
-   `options` **[Object][4]** Optional parameters (optional, default `{}`)
    -   `options.units` **[string][5]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)

### Examples

```javascript
var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};

var distance = turf.distance(from, to, options);

//addToMap
var addToMap = [from, to];
from.properties.distance = distance;
to.properties.distance = distance;
```

Returns **[number][6]** distance between the two points

[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2

[2]: http://en.wikipedia.org/wiki/Haversine_formula

[3]: https://tools.ietf.org/html/rfc7946#section-3.1.1

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->

---

This module is part of the [Turfjs project](http://turfjs.org/), an open source
module collection dedicated to geographic algorithms. It is maintained in the
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
PRs and issues.

### Installation

Install this module individually:

```sh
$ npm install @spatial/distance
```

Or install the Turf module that includes it as a function:

```sh
$ npm install @turf/turf
```

---
_Source: https://npm.io/package/@spatial/distance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
