haversine-distance
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

haversine-distance

build status Version

js-standard-style

Haversine formula in Javascript. In meters. Nothing more.

Example

Import

const haversine = require('haversine-distance')
// or
import haversine from 'haversine-distance'

Usage

const a = { latitude: 37.8136, longitude: 144.9631 }
const b = { latitude: 33.8650, longitude: 151.2094 }
 
console.log(haversine(a, b)) // 714504.18 (in meters)

Alternative forms such as lat, lng and lon work too, with mixed support:

const a = { lat: 37.8136, lng: 144.9631 }
const b = { lat: 33.8650, lon: 151.2094 }
 
console.log(haversine(a, b)) // 714504.18 (in meters)

GeoJSON support

const a = [144.9631, 37.8136]
const b = [151.2094, 33.865]
 
console.log(haversine(a, b)) // 714504.18 (in meters)

License MIT

Package Sidebar

Install

npm i haversine-distance

Weekly Downloads

27,986

Version

1.2.1

License

MIT

Unpacked Size

4.59 kB

Total Files

5

Last publish

Collaborators

  • dcousens