summaryrefslogtreecommitdiff
path: root/dashboard_website/static/js/utils.js
blob: 83e639790ad410b8b8fe8f19132f1afe8e8c4986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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;
}