summaryrefslogtreecommitdiff
path: root/src/helper.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/helper.js')
-rw-r--r--src/helper.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/helper.js b/src/helper.js
index 3bdbf7e..2242d91 100644
--- a/src/helper.js
+++ b/src/helper.js
@@ -43,4 +43,25 @@ export function timeConverter(UNIX_timestamp) {
function formatInt(num) {
return ("00" + num).slice(-2)
-} \ No newline at end of file
+}
+
+export function calcCrow(lat1, lon1, lat2, lon2)
+ {
+ var R = 6371; // km
+ var dLat = toRad(lat2-lat1);
+ var dLon = toRad(lon2-lon1);
+ var lat1 = toRad(lat1);
+ var lat2 = toRad(lat2);
+
+ var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
+ Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+ var d = R * c;
+ return d;
+ }
+
+ // Converts numeric degrees to radians
+ function toRad(Value)
+ {
+ return Value * Math.PI / 180;
+ } \ No newline at end of file