Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="ro">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Calculator Distanță QTH</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- text-align: center;
- margin-top: 50px;
- }
- input, button {
- padding: 8px;
- margin: 5px;
- }
- </style>
- </head>
- <body>
- <h1>Calculator Distanță QTH</h1>
- <label for="qth1">QTH Locator 1:</label>
- <input type="text" id="qth1" placeholder="Ex. JN48QM"><br>
- <label for="qth2">QTH Locator 2:</label>
- <input type="text" id="qth2" placeholder="Ex. KN25UD"><br>
- <button onclick="calculateDistance()">Calculează Distanța</button>
- <p id="result"></p>
- <script>
- // Funcție pentru a converti QTH locator în latitudine și longitudine
- function qthToLatLon(qth) {
- if (qth.length < 6) return null;
- qth = qth.toUpperCase();
- const fieldLon = (qth.charCodeAt(0) - 65) * 20 - 180; // Primele 2 caractere (câmp)
- const fieldLat = (qth.charCodeAt(1) - 65) * 10 - 90;
- const squareLon = parseInt(qth.charAt(2)) * 2; // Următoarele 2 cifre (pătrat)
- const squareLat = parseInt(qth.charAt(3)) * 1;
- const subSquareLon = (qth.charCodeAt(4) - 65) * (2 / 24); // Ultimele 2 litere (subpătrat)
- const subSquareLat = (qth.charCodeAt(5) - 65) * (1 / 24);
- const lon = fieldLon + squareLon + subSquareLon + (2 / 24 / 2); // Centrul subpătratului
- const lat = fieldLat + squareLat + subSquareLat + (1 / 24 / 2);
- return { lat, lon };
- }
- // Funcție pentru calculul distanței Haversine
- function haversineDistance(lat1, lon1, lat2, lon2) {
- const R = 6371; // Raza Pământului în kilometri
- const dLat = (lat2 - lat1) * Math.PI / 180;
- const dLon = (lon2 - lon1) * Math.PI / 180;
- const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
- Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
- Math.sin(dLon / 2) * Math.sin(dLon / 2);
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- return R * c; // Distanța în kilometri
- }
- // Funcție principală pentru calcul
- function calculateDistance() {
- const qth1 = document.getElementById("qth1").value.trim();
- const qth2 = document.getElementById("qth2").value.trim();
- const resultElement = document.getElementById("result");
- if (qth1.length < 6 || qth2.length < 6) {
- resultElement.textContent = "Te rog introdu locatoare QTH valide (ex. JN48QM).";
- return;
- }
- const coord1 = qthToLatLon(qth1);
- const coord2 = qthToLatLon(qth2);
- if (!coord1 || !coord2) {
- resultElement.textContent = "Locatoare QTH invalide.";
- return;
- }
- const distance = haversineDistance(coord1.lat, coord1.lon, coord2.lat, coord2.lon);
- resultElement.textContent = `Distanța între ${qth1} și ${qth2} este de ${distance.toFixed(2)} km.`;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement