Skip to content

Commit 72d133f

Browse files
committed
distance calculator added
1 parent b0902f8 commit 72d133f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

services/garage.service.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,25 @@ const ReturnCoords=async()=>
4747
return coords;
4848
}
4949

50+
const DistanceCal=(lat1,lat2, lon1, lon2)=>
51+
{
52+
lon1 = lon1 * Math.PI / 180;
53+
lon2 = lon2 * Math.PI / 180;
54+
lat1 = lat1 * Math.PI / 180;
55+
lat2 = lat2 * Math.PI / 180;
56+
let dlon = lon2 - lon1;
57+
let dlat = lat2 - lat1;
58+
let a=Math.pow(Math.sin(dlat / 2), 2)+ Math.cos(lat1) * Math.cos(lat2)* Math.pow(Math.sin(dlon / 2),2);
59+
let c=2 * Math.asin(Math.sqrt(a));
60+
let r=6371;
61+
return(c * r);
62+
}
5063

5164
module.exports = {
5265
AddGarage,
5366
FindGarage,
5467
AllGarages,
5568
DeleteGarage,
56-
ReturnCoords
69+
ReturnCoords,
70+
DistanceCal
5771
};

0 commit comments

Comments
 (0)