gps-distance的Typescript重构版
npm install gps-distance-es
gps-distance-es
支持两种调用方式,如果是测量两点距离,可以用 (source_lat, source_lon, destination_lat, destination_lon)
方式调用,如果要计算多点组成的路径长度,则可以传入一个 [lat,lon]
格式的数组。详见下方示例。
import distance from 'gps-distance-es';
// 计算两点距离:
const result = distance(45.527517, -122.718766, 45.373373, -121.693604);
// 81.78450202539503
import distance, { Point } from 'gps-distance-es';
// 计算多点路径的长度:
const path:Point[] = [
[45.527517, -122.718766],
[45.373373, -121.693604],
[45.527517, -122.718766]
];
var result2 = distance(path);
// 163.56900405079006
距离利用半正矢公式计算,返回单位为公里,所以计算结果仅为大致距离,不能代表精确距离。