gps-distance
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "gps-distance", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Node module for computing distances between GPS coordinates", | ||
@@ -10,3 +10,3 @@ "private": false, | ||
}, | ||
"main": "distance", | ||
"main": "lib/distance", | ||
"repository": { | ||
@@ -18,8 +18,11 @@ "type": "git", | ||
"mocha": ">= 1.9.0", | ||
"should": ">= 1.2.2" | ||
"should": ">= 1.2.2", | ||
"gpx-stream": "0.0.1" | ||
}, | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"keywords": [ | ||
"gps", "coordinates", "distance", "haversine" | ||
"gps", | ||
"coordinates", | ||
"distance", | ||
"haversine" | ||
], | ||
@@ -26,0 +29,0 @@ "author": "Maciej Adwent (http://github.com/Maciek416)", |
@@ -8,5 +8,17 @@ gps-distance | ||
Example | ||
------- | ||
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 | ||
@@ -16,11 +28,14 @@ | ||
// Between two points: | ||
// Measure between two points: | ||
var result = distance(45.527517, -122.718766, 45.373373, -121.693604); | ||
// result is 81.78450202539503 | ||
``` | ||
Array of GPS points | ||
------------------- | ||
// Along a path: | ||
```javascript | ||
// Measure a list of GPS points along a path: | ||
var path = [ | ||
@@ -35,8 +50,37 @@ [45.527517, -122.718766], | ||
// 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. | ||
Distances are returned in kilometers and computed using the Haversine formula. |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var distance = require('../lib/distance'); | ||
var gpx = require('gpx-stream'); | ||
var fs = require('fs'); | ||
@@ -35,10 +37,21 @@ describe('gps-distance', function() { | ||
var path = [ | ||
[45.527517, -122.718766], | ||
[45.373373, -121.693604], | ||
[45.527517, -122.718766] | ||
]; | ||
var libResult = distance(path); | ||
libResult.should.be.approximately(81.784 * 2, 0.1); | ||
done(); | ||
var points = new gpx(); | ||
var source = fs.createReadStream('./test/oregon.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(){ | ||
distance(path).should.be.approximately(7.7, 0.1); | ||
done(); | ||
}); | ||
@@ -45,0 +58,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159889
8
70
84
3
2