# gps-distance

> Node module for computing distances between GPS coordinates

Latest version **0.0.4** (published 2015-04-21) · BSD license · 0 weekly downloads

## Install

```sh
npm install gps-distance
pnpm add gps-distance
yarn add gps-distance
bun add gps-distance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2015-04-21 |
| First published | 2014-01-24 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.x |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Maciej Adwent |
| Maintainers | maciek416 |
| Keywords | gps, coordinates, distance, haversine |

## Links

- npm: https://www.npmjs.com/package/gps-distance
- Repository: https://github.com/Maciek416/gps-distance
- Issues: https://github.com/Maciek416/gps-distance/issues
- npm.io page: https://npm.io/package/gps-distance

## Recent versions

- 0.0.4 (latest) — 2015-04-21
- 0.0.3 — 2014-01-30
- 0.0.2 — 2014-01-24
- 0.0.1 — 2014-01-24

## README

gps-distance
============

[![NPM](https://nodei.co/npm/gps-distance.png)](https://nodei.co/npm/gps-distance/)

A node module for performing distance calculations between GPS coordinates

Installation
------------

```
npm install gps-distance
```

Examples
========

`gps-distance` supports two syntaxes for convenience. You can measure just between two points and supply in your GPS coordinates as direct arguments to distance in the form `(source_lat, source_lon, destination_lat, destination_lon)`, or you can use an array of points each in `[lat,lon]` format. See the examples below.

Point to Point
--------------

```javascript

var distance = require('gps-distance');

// Measure between two points:
var result = distance(45.527517, -122.718766, 45.373373, -121.693604);

// result is 81.78450202539503
```

Array of GPS points
-------------------

```javascript

// Measure a list of GPS points along a path:
var path = [
  [45.527517, -122.718766],
  [45.373373, -121.693604],
  [45.527517, -122.718766]
];

var result2 = distance(path);

// result2 is 163.56900405079006
```

Measuring Distance From a .GPX File
-----------------------------------

To compute the distance travelled in a tracked GPX file, use `gps-distance` with the `gpx-stream` module ( http://npmjs.org/package/gpx-stream/ ).

```javascript

var GPXstream = require('gpx-stream');
var distance = require('gps-distance');

var points = new GPXstream();
var source = fs.createReadStream('./marathon.gpx');
var path = [];

source.pipe(points);

points.on('readable', function() {
  var point;

  while(point = points.read()) {
    path.push([point.lat, point.lon]);
  }
});

points.on('end', function() {
  console.log('Distance travelled: ' + distance(path) + ' km');
});
```


Notes
-----

Distances are returned in kilometers and computed using the Haversine formula.

---
_Source: https://npm.io/package/gps-distance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
