Fast haversine
The fastest implementation of the haversine algorithm to calculate distances between to coordinates.
Install
npm install fast-haversine
Basic usage
Given two coordinates, i.e. departure and arrival of a infamous helicopter trip, calculate the distance in meters:
const distance = ; const from = lat: -34607814 lon: -58370301 ;const to = lat: -345161001 lon: -584847728 ; ; // quickly returns 14640 m
API
distance(from, to)
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.
Benchmarks
Like benchmarks? Then run 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%' } ]