Advertisement
yo9gjx

Calculator Distanță QTH

Mar 29th, 2025
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.34 KB | Sports | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ro">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Calculator Distanță QTH</title>
  7.     <style>
  8.         body {
  9.             font-family: Arial, sans-serif;
  10.             text-align: center;
  11.             margin-top: 50px;
  12.         }
  13.         input, button {
  14.             padding: 8px;
  15.             margin: 5px;
  16.         }
  17.     </style>
  18. </head>
  19. <body>
  20.     <h1>Calculator Distanță QTH</h1>
  21.     <label for="qth1">QTH Locator 1:</label>
  22.     <input type="text" id="qth1" placeholder="Ex. JN48QM"><br>
  23.     <label for="qth2">QTH Locator 2:</label>
  24.     <input type="text" id="qth2" placeholder="Ex. KN25UD"><br>
  25.     <button onclick="calculateDistance()">Calculează Distanța</button>
  26.     <p id="result"></p>
  27.  
  28.     <script>
  29.         // Funcție pentru a converti QTH locator în latitudine și longitudine
  30.         function qthToLatLon(qth) {
  31.             if (qth.length < 6) return null;
  32.  
  33.             qth = qth.toUpperCase();
  34.             const fieldLon = (qth.charCodeAt(0) - 65) * 20 - 180; // Primele 2 caractere (câmp)
  35.             const fieldLat = (qth.charCodeAt(1) - 65) * 10 - 90;
  36.             const squareLon = parseInt(qth.charAt(2)) * 2; // Următoarele 2 cifre (pătrat)
  37.             const squareLat = parseInt(qth.charAt(3)) * 1;
  38.             const subSquareLon = (qth.charCodeAt(4) - 65) * (2 / 24); // Ultimele 2 litere (subpătrat)
  39.             const subSquareLat = (qth.charCodeAt(5) - 65) * (1 / 24);
  40.  
  41.             const lon = fieldLon + squareLon + subSquareLon + (2 / 24 / 2); // Centrul subpătratului
  42.             const lat = fieldLat + squareLat + subSquareLat + (1 / 24 / 2);
  43.  
  44.             return { lat, lon };
  45.         }
  46.  
  47.         // Funcție pentru calculul distanței Haversine
  48.         function haversineDistance(lat1, lon1, lat2, lon2) {
  49.             const R = 6371; // Raza Pământului în kilometri
  50.             const dLat = (lat2 - lat1) * Math.PI / 180;
  51.             const dLon = (lon2 - lon1) * Math.PI / 180;
  52.             const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
  53.                       Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
  54.                       Math.sin(dLon / 2) * Math.sin(dLon / 2);
  55.             const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  56.             return R * c; // Distanța în kilometri
  57.         }
  58.  
  59.         // Funcție principală pentru calcul
  60.         function calculateDistance() {
  61.             const qth1 = document.getElementById("qth1").value.trim();
  62.             const qth2 = document.getElementById("qth2").value.trim();
  63.             const resultElement = document.getElementById("result");
  64.  
  65.             if (qth1.length < 6 || qth2.length < 6) {
  66.                 resultElement.textContent = "Te rog introdu locatoare QTH valide (ex. JN48QM).";
  67.                 return;
  68.             }
  69.  
  70.             const coord1 = qthToLatLon(qth1);
  71.             const coord2 = qthToLatLon(qth2);
  72.  
  73.             if (!coord1 || !coord2) {
  74.                 resultElement.textContent = "Locatoare QTH invalide.";
  75.                 return;
  76.             }
  77.  
  78.             const distance = haversineDistance(coord1.lat, coord1.lon, coord2.lat, coord2.lon);
  79.             resultElement.textContent = `Distanța între ${qth1} și ${qth2} este de ${distance.toFixed(2)} km.`;
  80.         }
  81.     </script>
  82. </body>
  83. </html>
  84.  
Tags: QTH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement