A Small Utility to calulate distance from a latitude and longitude points.
Warning Javascript in general is not the greatest at math when dealing with large numbers... You have been warned
Distance().from([lat, lng]).to([lat, lng]).unit('miles')
// returns kilometers by default
var home = Distance().from([lat, lng]);
var nearby = [];
var locations = [/*...*/];
for(var i = 0; i < locations.length; i += 1){
var location = locations[i];
// use the same instance over and over
if(home.to(location.center).unit('miles') < 3){
nearby.push(location)
}
}
- kilometers
- miles
- feet
Unit conversion is handled in the prototype of Number
and is subject to change
All new features for distance.js must be accompanied by a test to prove feature works. Bug fixes do not need new test but it is recommended.
npm install
grunt build
grunt test