Skip to main content
Version: 7.3.0

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

名称类型描述
fromCoord原点坐标
toCoord目的地坐标
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(...);