-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
156 lines (150 loc) · 4.56 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<html>
<head>
<title>Distance Calculator</title>
<style>
body {
background-color: #f4f4f4;
font-family: monospace;
}
#calculator {
display: flex;
flex-direction: column;
align-items: center;
background-color: #f5f5f5;
border: 1px solid #dddddd;
border-radius: 10px;
padding: 20px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}
#locationInput, #locationInput2 {
border: 1px solid #dddddd;
border-radius: 5px;
padding: 10px;
margin-bottom: 20px;
width: 300px;
font-size: 16px;
outline: none;
}
button {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
margin: 5px;
cursor: pointer;
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.2);
}
button:hover {
background-color: #3e8e41;
}
#result, #waitTime {
margin-top: 30px;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="calculator">
<h2>Distance Calculator</h2>
<p>Enter the latitude and longitude of two points separated by a comma:</p>
<input type="text" id="locationInput" placeholder="First point: latitude, longitude">
<input type="text" id="locationInput2" placeholder="Second point: latitude, longitude">
<button onclick="calculateDistance()">Calculate Distance</button>
<p id="result"></p>
<p id="waitTime"></p>
</div>
<script>
function calculateDistance() {
const location1 = document.getElementById("locationInput").value.split(",");
const location2 = document.getElementById("locationInput2").value.split(",");
// Check if input boxes are empty
if (location1.length < 2 || location2.length < 2) {
return;
}
const lat1 = parseFloat(location1[0]) * (Math.PI / 180);
const lon1 = parseFloat(location1[1]) * (Math.PI / 180);
const lat2 = parseFloat(location2[0]) * (Math.PI / 180);
const lon2 = parseFloat(location2[1]) * (Math.PI / 180);
const R = 3959; // Radius of the Earth in miles
const dLat = lat2 - lat1;
const dLon = lon2 - lon1;
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1) * Math.cos(lat2) *
Math.sin(dLon / 2) * Math.sin(dLon / 2)
;
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = R * c; // Distance in miles
const resultElement = document.getElementById("result");
resultElement.innerHTML = `The distance between the two points is ${distance.toFixed(2)} miles`;
let waitTime = 0;
if (distance <= 1) {
waitTime = 30;
} else if (distance <= 5) {
waitTime = 2.5 * 60;
} else if (distance <= 10) {
waitTime = 7 * 60;
} else if (distance <= 12) {
waitTime = 8 * 60;
} else if (distance <= 18) {
waitTime = 10 * 60;
} else if (distance <= 26) {
waitTime = 15 * 60;
} else if (distance <= 42) {
waitTime = 19 * 60;
} else if (distance <= 65) {
waitTime = 22 * 60;
} else if (distance <= 81) {
waitTime = 25 * 60;
} else if (distance <= 100) {
waitTime = 35 * 60;
} else if (distance <= 250) {
waitTime = 45 * 60;
} else if (distance <= 375) {
waitTime = 54 * 60;
} else if (distance <= 460) {
waitTime = 62 * 60;
} else if (distance <= 565) {
waitTime = 69 * 60;
} else if (distance <= 700) {
waitTime = 78 * 60;
} else if (distance <= 800) {
waitTime = 84 * 60;
} else if (distance <= 900) {
waitTime = 92 * 60;
} else if (distance <= 1000) {
waitTime = 99 * 60;
} else if (distance <= 1300) {
waitTime = 117 * 60;
} else if (distance <= 1500) {
waitTime = 2 * 60 * 60;
} else {
waitTime = 2 * 60 * 60; // if distance is greater than 1500km, set wait time to 2 hours
}
const waitTimeInSeconds = Math.floor(waitTime);
const waitTimeInMinutes = Math.floor(waitTime / 60);
const waitTimeInHours = Math.floor(waitTime / 3600);
const remainingSeconds = waitTimeInSeconds % 60;
const remainingMinutes = waitTimeInMinutes % 60;
let waitTimeElement = document.getElementById("waitTime");
if (waitTime <= 60) {
waitTimeElement.innerHTML = `Wait time: ${waitTimeInSeconds} seconds`;
} else if (waitTime <= 3600) {
waitTimeElement.innerHTML = `Wait time: ${waitTimeInMinutes} minutes ${remainingSeconds} seconds`;
} else {
waitTimeElement.innerHTML = `Wait time: ${waitTimeInHours} hours ${remainingMinutes} minutes ${remainingSeconds} seconds`;
}
}
</script>
</body>
</html>
<!--
54.584171, -94.842305
61.657736, 139.632741
-->