distance
描述
🌐 Description
计算两个坐标之间的距离,可选择以度、弧度、英里或公里为单位。 这使用哈弗辛公式来考虑地球的曲率。
🌐 Calculates the distance between two coordinates in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
参数
🌐 Parameters
| 名称 | 类型 | 描述 |
|---|---|---|
| from | Coord | 原点坐标 |
| to | Coord | 目的地坐标 |
| options? | Object | 可选参数 (默认 {}) |
| options.units? | Units | 支持所有有效的 Turf 单位。(默认 '公里') |
返回
🌐 Returns
number 两个坐标之间的距离
示例
🌐 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(...);