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
var distance = ; // Measure between two points:var result = ; // result is 81.78450202539503
Array of GPS points
// Measure a list of GPS points along a path:var path = 45527517 -122718766 45373373 -121693604 45527517 -122718766; var result2 = ; // 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/ ).
var GPXstream = ;var distance = ; var points = ;var source = fs;var path = ; source; points; points;
Notes
Distances are returned in kilometers and computed using the Haversine formula.