A wrapper for haversine and vincenty distance formulas
npm install node-geo-distancewrapper for http://jsperf.com/vincenty-vs-haversine-distance-calculations,
all credit for code to author of that link
$ npm install node-geo-distance --savejs
var geo = require('node-geo-distance');
--> {latitude:x, longitude:x}, {latitude:x, longitude:x}, callback(dist)
geo.vincenty(coord1, coord2, callback)
--> {latitude:x, longitude:x}, {latitude:x, longitude:x}
geo.vincentySync(coord1, coord2)
--> {latitude:x, longitude:x}, {latitude:x, longitude:x}, callback(dist)
geo.haversine(coord1, coord2, callback)
--> {latitude:x, longitude:x}, {latitude:x, longitude:x}
geo.haversineSync(coord1, coord2)
`$3
`js
var geo = require('node-geo-distance');// White house
var coord1 = {
latitude: 38.8977330,
longitude: -77.0365310
}
// Washington Monument
var coord2 = {
latitude: 38.8894840,
longitude: -77.0352790
}
geo.vincenty(coord1, coord2, function(dist) {
console.log(dist);
});
var vincentyDist = geo.vincentySync(coord1, coord2);
geo.haversine(coord1, coord2, function(dist) {
console.log(dist);
});
var haversineDist = geo.haversineSync(coord1, coord2);
``