3.0.12 • Published 8 years ago

turf-distance v3.0.12

Weekly downloads
13,292
License
MIT
Repository
github
Last release
8 years ago

turf-distance

build status

turf distance module

turf.distance(from, to, [units=kilometers])

Calculates the distance between two Point|points in degress, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

Parameters

parametertypedescription
fromFeature.\<Point>origin point
toFeature.\<Point>destination point
[units=kilometers]Stringoptional: can be degrees, radians, miles, or kilometers

Example

var point1 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.343, 39.984]
  }
};
var point2 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.534, 39.123]
  }
};
var units = "miles";

var points = {
  "type": "FeatureCollection",
  "features": [point1, point2]
};

//=points

var distance = turf.distance(point1, point2, units);

//=distance

Returns Number, distance between the two points

Installation

Requires nodejs.

$ npm install turf-distance

Tests

$ npm test