Skip to main content
Version: Next

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

NameTypeDescription
fromCoord | Pointorigin point or coordinate
toCoord | Pointdestination point or coordinate
options?ObjectOptional parameters (default {})
options.units?stringcan 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(...);