summaryrefslogtreecommitdiff
path: root/static/js/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/utils.js')
-rw-r--r--static/js/utils.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/static/js/utils.js b/static/js/utils.js
new file mode 100644
index 0000000..83e6397
--- /dev/null
+++ b/static/js/utils.js
@@ -0,0 +1,18 @@
+function deg2rad(deg) {
+ return deg * (Math.PI/180)
+}
+function getDistanceFromLatLon(item1, item2) {
+ lat1 = item1['latitude']; lon1 = item1['longitude'];
+ lat2 = item2['latitude']; lon2 = item2['longitude'];
+ var R = 3958.8; // Radius of the earth
+ var dLat = deg2rad(lat2-lat1);
+ var dLon = deg2rad(lon2-lon1);
+ var a =
+ Math.sin(dLat/2) * Math.sin(dLat/2) +
+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
+ Math.sin(dLon/2) * Math.sin(dLon/2)
+ ;
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+ var d = R * c; // Distance in mi
+ return d;
+} \ No newline at end of file