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? | 单位 | 支持所有有效的 Turf 单位。(默认 '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(...);