From 20cdcb929b4bd364c1d586df2f7c2b241dffe7ea Mon Sep 17 00:00:00 2001 From: Ayush Sharma <104761315+ayush-1s@users.noreply.github.com> Date: Mon, 30 Oct 2023 00:32:54 +0530 Subject: [PATCH] Added coordinate distance calculator (#110) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ayush-1s Co-authored-by: Ruan Aragão --- .../index.html | 22 +++++ .../script.js | 31 +++++++ .../style.css | 55 ++++++++++++ index.html | 84 ++++++++++--------- 4 files changed, 151 insertions(+), 41 deletions(-) create mode 100644 calculators/Distance-between-two-coordinates-calculator/index.html create mode 100644 calculators/Distance-between-two-coordinates-calculator/script.js create mode 100644 calculators/Distance-between-two-coordinates-calculator/style.css diff --git a/calculators/Distance-between-two-coordinates-calculator/index.html b/calculators/Distance-between-two-coordinates-calculator/index.html new file mode 100644 index 0000000..d7098d8 --- /dev/null +++ b/calculators/Distance-between-two-coordinates-calculator/index.html @@ -0,0 +1,22 @@ + + + + + + +

Coordinate Distance Calculator

+
+ + + + + + + + + +
+
+ + + diff --git a/calculators/Distance-between-two-coordinates-calculator/script.js b/calculators/Distance-between-two-coordinates-calculator/script.js new file mode 100644 index 0000000..aef92ae --- /dev/null +++ b/calculators/Distance-between-two-coordinates-calculator/script.js @@ -0,0 +1,31 @@ +function calculateDistance() { + const lat1 = parseFloat(document.getElementById('lat1').value); + const lon1 = parseFloat(document.getElementById('lon1').value); + const lat2 = parseFloat(document.getElementById('lat2').value); + const lon2 = parseFloat(document.getElementById('lon2').value); + + if (isNaN(lat1) || isNaN(lon1) || isNaN(lat2) || isNaN(lon2)) { + document.getElementById('result').textContent = 'Please enter valid coordinates.'; + return; + } + + const earthRadius = 6371; // Earth's radius in kilometers + + const lat1Rad = toRadians(lat1); + const lat2Rad = toRadians(lat2); + const latDiff = toRadians(lat2 - lat1); + const lonDiff = toRadians(lon2 - lon1); + + const a = Math.sin(latDiff / 2) * Math.sin(latDiff / 2) + + Math.cos(lat1Rad) * Math.cos(lat2Rad) * + Math.sin(lonDiff / 2) * Math.sin(lonDiff / 2); + + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + const distance = earthRadius * c; + + document.getElementById('result').textContent = `Distance: ${distance.toFixed(2)} km`; +} + +function toRadians(degrees) { + return degrees * (Math.PI / 180); +} diff --git a/calculators/Distance-between-two-coordinates-calculator/style.css b/calculators/Distance-between-two-coordinates-calculator/style.css new file mode 100644 index 0000000..bfdf2e0 --- /dev/null +++ b/calculators/Distance-between-two-coordinates-calculator/style.css @@ -0,0 +1,55 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + background-color: #f1f1f1; + margin: 0; + padding: 0; +} + +h1 { + color: #333; +} + +.calculator { + background-color: #fff; + border-radius: 10px; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3); + padding: 20px; + width: 300px; + margin: 20px auto; +} + +label { + display: block; + margin-top: 10px; +} + +input { + width: 100%; + padding: 5px; + margin-top: 5px; + border: 1px solid #ccc; + border-radius: 3px; +} + +button { + background-color: #333; + color: white; + padding: 10px; + font-size: 16px; + border: none; + cursor: pointer; + border-radius: 5px; + margin-top: 10px; + width: 100%; +} + +button:hover { + background-color: #444; +} + +#result { + font-size: 20px; + color: #333; + margin: 20px; +} diff --git a/index.html b/index.html index 7c66dc0..9d61daf 100644 --- a/index.html +++ b/index.html @@ -1,45 +1,47 @@ - - - - - - + + + + + + - - - - - - Calcy — The Ultimate Calculator Collection - - -

Calculators

-
- - Example Calculator
- CGPA Calculator
- Currency Calculator
- Body Mass Index Calculator
- Bitwise calculator
- Age Calculator
- temperature Calculator
- Tip Calculator
- Pixel to Em Converter
- Count by Weight
- Discount Calculator
- Investment Calculator
- Number System Calculator
- Body-Fat-Calculator
- Compound Interest Calculator
- Quadratic Root Calculator
- COlor Converter
- 2-8-16 Calculator
- Distance Calculator
- Binary Operations Calculator
- General Calculator
- Unit Convertor
- + + + + + + + Calcy — The Ultimate Calculator Collection + + + +

Calculators

+
+ + Example Calculator
+ CGPA Calculator
+ Currency Calculator
+ Body Mass Index Calculator
+ Bitwise calculator
+ Age Calculator
+ temperature Calculator
+ Tip Calculator
+ Pixel to Em Converter
+ Count by Weight
+ Discount Calculator
+ Investment Calculator
+ Number System Calculator
+ Body-Fat-Calculator
+ Compound Interest Calculator
+ Quadratic Root Calculator
+ COlor Converter
+ 2-8-16 Calculator
+ Distance Calculator
+ Binary Operations Calculator
+ Unit Convertor
+ Coordinate Distance Calculator +