/latlongulator

NPM Package About Geo Calculation Operations

Primary LanguageTypeScript

LatLongulator Package


The NPM package which presents utils for geo calculation operations.


Getting the distance between 2 locations:

  • By Kilometers (km)
// Async Version
getDistanceByKilometers(
  { lattitude: 43.6426723, longtitude: 44.2531532 },
  { lattitude: 50.9483754, longtitude: 49.3948516 },
  function (err, res) {
    if (err) return err;
    console.log(res);
  }
);

// Sync Version
getDistanceByKilometersSync(
  { lattitude: 43.6426723, longtitude: 44.2531532 },
  { lattitude: 50.9483754, longtitude: 49.3948516 }
);

  • By Miles (ml)
// Same code structure like above with names getDistanceByMiles and getDistanceByMilesSync

Note: Location point should be declared like below

{
    lattitude: number,
    longtitude: number
}

Converters between kilometers and miles scales:

  • From kilometers to miles
const km = 2.4;
const miles = kilometers2miles(km);
  • From miles to kilometers
const ml = 4.5;
const kilometers = miles2kilometers(ml);