Measures the straight-line distance between two points, like cities or landmarks.
npm install @turf/distanceCalculates the distance between two [coordinates][1] in degrees, radians, miles, or kilometers.
This uses the [Haversine formula][2] to account for global curvature.
* from [Coord][1] origin coordinate
* to [Coord][1] destination coordinate
* options [Object][3] Optional parameters (optional, default {})
* options.units Units Supports all valid Turf [Units][4]. (optional, default 'kilometers')
``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][5] distance between the two coordinates
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.1
[2]: http://en.wikipedia.org/wiki/Haversine_formula
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[4]: https://turfjs.org/docs/api/types/Units
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
---
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this single module individually:
`sh`
$ npm install @turf/distance
Or install the all-encompassing @turf/turf module that includes all modules as functions:
`sh``
$ npm install @turf/turf