pincode-distance-calculator

node package to calculate the distance between two pincodes.

Usage no npm install needed!

<script type="module">
  import pincodeDistanceCalculator from 'https://cdn.skypack.dev/pincode-distance-calculator';
</script>

README

PINCODE DISTANCE CALCULATOR

Thanks for visiting by mistake.

Installation

npm install pincode-distance-calculator

Usage

const Distance = require('pincode-distance-calculator')

let result = Distance.getDistance(110045,643231) 
//console logging result will return promise { <pending> }

result.then((distance) =>{
    console.log(distance) // will console log the distance
})

Theory

The Distance calculator takes two pincodes as arguments in the getDistance function. An API call is made to get the latlong data of both the pincodes.

The distance is calculated using the Haversine formula which is used to calculate distance between two co-ordintes on a sphere. more on Haversine Formula


Caveats

NOTE : The distance which is returned is not the distance by road, it is instead a distance between two points using a straight line.

image

The function will return the path2 distance in most cases.

This package is good to calculate a distance matrix for comparisons from a single origin. For example :

we have 3 origins and 1 destination, this package can be used to find the closest pincode to that destination.