geo-distances

1.0.6 • Public • Published

geo-distances

A geographical distance calculator. Calculates distance between two points in a defined range using haversine formula.

Installation

Install using npm:

$ npm install geo-distances

Example

To get the distance between two points in Kilometers (KM), define starting point and end point in data.json file. Range and Unit of distance can be set as per requirement.


let geoDistances = require('geo-distances'),

starting_point = { "latitude": "53.339428", "longitude": "-6.257664" },
range = '100',
unit = 'km',
filepath = __dirname+'/data.json';

//example data.json
data.json = [{ "latitude": "53.038056", "longitude": "-7.653889" }]

let distances = geoDistances(filepath, starting_point, range, unit);
console.log(distances);

Usage

geo-distances(start, end, [options])

The following types are accepted in the unit option:

  • miles or mi

  • yards

  • feet

  • kilometers or km

  • meters

Example:

starting_point = { "latitude": "57.319428", "longitude": "-2.2571864" },

filepath = __dirname+'/data.json', //remember to provide an array of Objects
unit = 'mi',
range = '10000';

let geoDistances = require('geo-distances')
let distances = geoDistances(filepath, starting_point, range, unit);

//example data.json
data.json = [{ "latitude": "50.9096375", "longitude": "-4.043701" }];

Package Sidebar

Install

npm i geo-distances

Weekly Downloads

7

Version

1.0.6

License

MIT

Unpacked Size

6.63 kB

Total Files

5

Last publish

Collaborators

  • pranavstark