The fastest implementation of the haversine algorithm to calculate distances between to coordinates.
npm install fast-haversine
Given two coordinates, i.e. departure and arrival of a infamous helicopter trip, calculate the distance in meters:
const distance = require("fast-haversine");
const from = { lat: -34.607814, lon: -58.370301 };
const to = { lat: -34.5161001, lon: -58.4847728 };
distance(from, to); // quickly returns 14640 m
Calculates the distance between the to given coordinates.
The coordinates are objects containing lat
and lon
properties.
Returns a number representing the distance in meters.
For insights on the development of this library and how it was optimized, take a look at this post:
https://blog.utoctadel.com.ar/2016/05/20/fast-haversine.html
And if you want to run the benchmanks by yourself, try npm run benchmark
.
Current results are:
$ npm run benchmark
[ { name: '../lib', time: '100%', dist: '100%' },
{ name: 'haversine-distance', time: '139%', dist: '99%' },
{ name: 's-haversine', time: '151%', dist: '99%' },
{ name: 'gps-distance', time: '163%', dist: '99%' },
{ name: 'haversine', time: '190%', dist: '99%' },
{ name: 'geodesy', time: '221%', dist: '99%' },
{ name: 'coordist', time: '302%', dist: '100%' },
{ name: 'geodist', time: '307%', dist: '99%' },
{ name: 'node-geo-distance', time: '535%', dist: '99%' },
{ name: 'jeyo-distans', time: '828%', dist: '99%' } ]