Node module for computing distances between GPS coordinates
A node module for performing distance calculations between GPS coordinates
npm install gps-distance
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.
var distance = require'gps-distance';// Measure between two points:var result = distance45.527517 -122.718766 45.373373 -121.693604;// result is 81.78450202539503
// Measure a list of GPS points along a path:var path =45.527517 -122.71876645.373373 -121.69360445.527517 -122.718766;var result2 = distancepath;// result2 is 163.56900405079006
To compute the distance travelled in a tracked GPX file, use
gps-distance with the
gpx-stream module ( http://npmjs.org/package/gpx-stream/ ).
var GPXstream = require'gpx-stream';var distance = require'gps-distance';var points = ;var source = fscreateReadStream'./marathon.gpx';var path = ;sourcepipepoints;pointson'readable'var point;whilepoint = pointsreadpathpushpointlat pointlon;;pointson'end'console.log'Distance travelled: ' + distancepath + ' km';;
Distances are returned in kilometers and computed using the Haversine formula.