Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including geo-distances with all npm packages installed. Try it out:

var geoDistances = require("geo-distances")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

geo-distances v1.0.6

A geographical distance calculator. Calculates distance between two points using haversine formula.

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" }];

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free