UNPKG

1.55 kBMarkdownView Raw
1# Haversine
2A simple haversine formula module for Node.js
3
4## Installation
5`$ npm install haversine`
6
7## Usage
8### haversine (start, end, options)
9
10 const haversine = require('haversine')
11
12 const start = {
13 latitude: 30.849635,
14 longitude: -83.24559
15 }
16
17 const end = {
18 latitude: 27.950575,
19 longitude: -82.457178
20 }
21
22 console.log(haversine(start, end))
23 console.log(haversine(start, end, {unit: 'mile'}))
24 console.log(haversine(start, end, {unit: 'meter'}))
25 console.log(haversine(start, end, {threshold: 1}))
26 console.log(haversine(start, end, {threshold: 1, unit: 'mile'}))
27 console.log(haversine(start, end, {threshold: 1, unit: 'meter'}))
28
29
30#### api
31- `options.unit` - Unit of measurement applied to result (default `km`, available `km, mile, meter, nmi`)
32- `options.threshold` - If passed, will result in library returning `boolean` value of whether or not the start and end points are within that supplied threshold. (default `null`)
33- `options.format` - The format of start and end coordinate arguments. See table below for available values. (default `null`)
34
35| Format | Example
36| ------------- |--------------------------|
37| `undefined` (default) | `{ latitude: 30.849635, longitude: -83.24559] }`
38| `[lat,lon]` | `[30.849635, -83.24559]`
39| `[lon,lat]` | `[-83.24559, 30.849635]`
40| `{lat,lon}` | `{ lat: 30.849635, lon: -83.24559] }`
41| `geojson` | `{ type: 'Feature', geometry: { coordinates: [-83.24559, 30.849635] } }`
42
43
44[MIT License](http://opensource.org/licenses/MIT)