Skip to main content
Version: 7.2.0

distance

描述

¥Description

计算两个 coordinates 之间的距离(以度、弧度、英里或公里为单位)。本模块使用 半正矢公式 来计算全局曲率。

¥Calculates the distance between two coordinates in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

参数

¥Parameters

名称类型描述
from坐标系原点坐标
to坐标系目标坐标
options?对象可选参数(默认 {})
options.units?string可以是度、弧度、英里或千米(默认 'kilometers')

返回

¥Returns

number 两者之间的距离坐标

¥number distance between the two coordinates

示例

¥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(...);