distance
Description
Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
Parameters
Name | Type | Description |
---|---|---|
from | Coord | Point | origin point or coordinate |
to | Coord | Point | destination point or coordinate |
options? | Object | Optional parameters (default {}) |
options.units? | string | can be degrees, radians, miles, or kilometers (default 'kilometers') |
Returns
number distance between the two points
Examples
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);
Installation
$ npm install @turf/distance
import { distance } from "@turf/distance";
const result = distance(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.distance(...);