programmieren:amateurfunk:locator
Locator Berechnung
Quelle: https://www.giangrandi.org/electronics/radio/qthloccalc.shtml
QTH locator calculator
Auch eine gute Quelle um die Entfernung zwischen zwei Locator's zu berechnen
https://www.karhukoti.com/Maidenhead-Grid-Square-Locator
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="author" content="Iacopo Giangrandi" />
<title>QTH locator calculator</title>
<style>
body { background-color:#c0c0c0; color:#000000; }
img { border:none; vertical-align:middle; }
table { border:none; }
table td { border:none; vertical-align:top; text-align:left; }
.table_with_border { border-style:outset; border-width:1px; border-spacing:2px; }
.table_with_border td { border-style:inset; border-width:1px; vertical-align:top; text-align:left; }
.table_footer { border:none; width:100%; text-align:center; }
.table_footer td { border:none; text-align:center; }
</style>
</head>
<body>
<!-- Written by Iacopo Giangrandi, http://www.giangrandi.ch -->
<h1>QTH locator calculator</h1>
<hr />
<form id="qth_locator">
<table class=table_with_border>
<tr>
<td colspan=3><b>Degrees-minutes-seconds format:</b></td>
</tr>
<tr>
<td style="text-align:right;">Latitude:</td>
<td><input size="1" id="lat_NS" type="text" />
<input size="3" id="lat_deg" type="text" /> °
<input size="3" id="lat_min" type="text" /> '
<input size="8" id="lat_sec" type="text" /> "</td>
<td rowspan=2 style="vertical-align:middle;"><input id="CalculateQTH" value="Convert" onclick="return cmd_calculate_qth_dec()" type="button" /></td>
</tr>
<tr>
<td style="text-align:right;">Longitude:</td>
<td><input size="1" id="lon_EW" type="text" />
<input size="3" id="lon_deg" type="text" /> °
<input size="3" id="lon_min" type="text" /> '
<input size="8" id="lon_sec" type="text" /> "</td>
</tr>
<tr>
<td colspan=3><b>Decimal format:</b></td>
</tr>
<tr>
<td style="text-align:right;">Latitude:</td>
<td><input size="10" id="lat_dec" type="text" /> ° Positive: North, negative: South.</td>
<td rowspan=2 style="vertical-align:middle;"><input id="CalculateQTHbis" value="Convert" onclick="return cmd_calculate_qth_dms()" type="button" /></td>
</tr>
<tr>
<td style="text-align:right;">Longitude</td>
<td><input size="10" id="lon_dec" type="text" /> ° Positive: East, negative: West.</td>
</tr>
<tr>
<td colspan=3><b>QTH locator:</b></td>
</tr>
<tr>
<td>Locator string:</td>
<td><input size="10" id="qth_loc" type="text" /></td>
<td><input id="CalculateLatLon" value="Convert" onclick="return cmd_calculate_dec_dms()" type="button" /></td>
</tr>
<tr>
<td colspan=3><input id="get_location" onclick="return cmd_get_location()" type=button value="Get current location" /></td>
</tr>
</table>
</form>
<hr />
<script>
<!--
// --------------------------------------------------------------------------
// A few points to check if the algorithm works:
// N 48.396, E 11.458, JN58rj
// S 30.688, E 25.208, KF29oh
// S 47.229, W 67.625, FE62es
// N 45.021, W 117.458, DN15ga
// --------------------------------------------------------------------------
var str_chr_up = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Constants.
var str_chr_lo = "abcdefghijklmnopqrstuvwxyz";
var str_num = "0123456789";
// --------------------------------------------------------------------------
function cmd_calculate_qth_dec()
{
var lat, lat_NS, lat_deg, lat_min, lat_sec;
var lon, lon_EW, lon_deg, lon_min, lon_sec
var qth;
lat_NS = document.getElementById('lat_NS').value; // Get data from the form.
lat_deg = document.getElementById('lat_deg').value;
lat_min = document.getElementById('lat_min').value;
lat_sec = document.getElementById('lat_sec').value;
lon_EW = document.getElementById('lon_EW').value;
lon_deg = document.getElementById('lon_deg').value;
lon_min = document.getElementById('lon_min').value;
lon_sec = document.getElementById('lon_sec').value;
lat_NS = lat_NS.toUpperCase();
lon_EW = lon_EW.toUpperCase();
if ((lat_NS != "N") && (lat_NS != "S")) // Check for valid latitude.
{
document.getElementById('lat_NS').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert('Invalid latitude: only "N" (North) or "S" (South)');
return(1);
}
if (isNaN(lat_deg) || (lat_deg > 90) || (lat_deg < 0) || (lat_deg == "") || (lat_deg != Math.floor(lat_deg)))
{
document.getElementById('lat_deg').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid latitude: please enter degrees between 0 and 90 (integer)");
return(1);
}
if (isNaN(lat_min) || (lat_min >= 60) || (lat_min < 0) || (lat_min == "") || (lat_min != Math.floor(lat_min)))
{
document.getElementById('lat_min').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid latitude: please enter minutes between 0 and 59 (integer)");
return(1);
}
if (isNaN(lat_sec) || (lat_sec >= 60) || (lat_sec < 0) || (lat_sec == ""))
{
document.getElementById('lat_sec').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid latitude: please enter seconds between 0 and 60");
return(1);
}
if ((lon_EW != "E") && (lon_EW != "W")) // Check for valid longitude.
{
document.getElementById('lon_EW').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert('Invalid longitude: only "E" (East) or "W" (West)');
return(1);
}
if (isNaN(lon_deg) || (lon_deg > 180) || (lon_deg < 0) || (lon_deg == "") || (lon_deg != Math.floor(lon_deg)))
{
document.getElementById('lon_deg').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid longitude: please enter degrees between 0 and 180 (integer)");
return(1);
}
if (isNaN(lon_min) || (lon_min >= 60) || (lon_min < 0) || (lon_min == "") || (lon_min != Math.floor(lon_min)))
{
document.getElementById('lon_min').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid longitude: please enter minutes between 0 and 59 (integer)");
return(1);
}
if (isNaN(lon_sec) || (lon_sec >= 60) || (lon_sec < 0) || (lon_sec == ""))
{
document.getElementById('lon_sec').value = "";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
alert("Invalid longitude: please enter seconds between 0 and 60");
return(1);
}
lat_deg = lat_deg * 1; // Make sure lat/lon are numbers.
lat_min = lat_min * 1;
lat_sec = lat_sec * 1;
lon_deg = lon_deg * 1;
lon_min = lon_min * 1;
lon_sec = lon_sec * 1;
lat = lat_deg + lat_min / 60 + lat_sec / 3600; // Calculate decimal lat/lon.
if (lat_NS == "S")
lat *= -1;
lon = lon_deg + lon_min / 60 + lon_sec / 3600;
if (lon_EW == "W")
lon *= -1;
document.getElementById('lat_dec').value = lat.toFixed(3); // Display decimal lat/lon (rounded to 3 decimal digits).
document.getElementById('lon_dec').value = lon.toFixed(3);
lat += 90; // Locator lat/lon origin shift.
lon += 180;
qth = str_chr_up.charAt(Math.floor(lon / 20)); // 1st digit: 20deg longitude slot.
qth += str_chr_up.charAt(Math.floor(lat / 10)); // 2nd digit: 10deg latitude slot.
qth += str_num.charAt(Math.floor((lon % 20) / 2)); // 3rd digit: 2deg longitude slot.
qth += str_num.charAt(Math.floor((lat % 10) / 1)); // 4th digit: 1deg latitude slot.
qth += str_chr_lo.charAt(Math.floor((lon % 2) * (60 / 5))); // 5th digit: 5min longitude slot.
qth += str_chr_lo.charAt(Math.floor((lat % 1) * (60 / 2.5))); // 6th digit: 2.5min latitude slot.
document.getElementById('qth_loc').value = qth; // Display QTH locator.
return(0);
}
// --------------------------------------------------------------------------
function cmd_calculate_qth_dms()
{
var lat, lon, qth;
var deg, min, sec;
lat = document.getElementById('lat_dec').value; // Get data from the form.
lon = document.getElementById('lon_dec').value;
if (isNaN(lat) || (lat > 90) || (lat < -90) || (lat == "")) // Check for valid latitude.
{
document.getElementById('lat_dec').value = "";
document.getElementById('qth_loc').value = "";
document.getElementById('lat_NS').value = "";
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
alert("Invalid latitude: please enter a value between -90 (S) and 90 (N) degrees");
return(1);
}
if (isNaN(lon) || (lon > 180) || (lon < -180) || (lon == "")) // Check for valid longitude.
{
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
document.getElementById('lat_NS').value = "";
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
alert("Invalid longitude: please enter a value between -180 (W) and 180 (E) degrees");
return(1);
}
lat = lat * 1; // Make sure lat/lon are numbers.
lon = lon * 1;
deg = Math.floor(Math.abs(lat)); // Convert latitude to deg/min/sec.
min = Math.floor((Math.abs(lat) - deg) * 60);
sec = Math.floor(((Math.abs(lat) - deg) * 60 - min) * 60);
if (lat >= 0)
document.getElementById('lat_NS').value = "N";
else
document.getElementById('lat_NS').value = "S";
document.getElementById('lat_deg').value = deg;
document.getElementById('lat_min').value = (min < 10 ? "0" : "") + min.toString();
document.getElementById('lat_sec').value = (sec < 10 ? "0" : "") + sec.toString();
deg = Math.floor(Math.abs(lon)); // Convert longitude to deg/min/sec.
min = Math.floor((Math.abs(lon) - deg) * 60);
sec = Math.floor(((Math.abs(lon) - deg) * 60 - min) * 60);
if (lon >= 0)
document.getElementById('lon_EW').value = "E";
else
document.getElementById('lon_EW').value = "W";
document.getElementById('lon_deg').value = deg;
document.getElementById('lon_min').value = (min < 10 ? "0" : "") + min.toString();
document.getElementById('lon_sec').value = (sec < 10 ? "0" : "") + sec.toString();
lat += 90; // Locator lat/lon shift.
lon += 180;
qth = str_chr_up.charAt(Math.floor(lon / 20)); // 1st digit: 20deg longitude slot.
qth += str_chr_up.charAt(Math.floor(lat / 10)); // 2nd digit: 10deg latitude slot.
qth += str_num.charAt(Math.floor((lon % 20) / 2)); // 3rd digit: 2deg longitude slot.
qth += str_num.charAt(Math.floor((lat % 10) / 1)); // 4th digit: 1deg latitude slot.
qth += str_chr_lo.charAt(Math.floor((lon % 2) * (60 / 5))); // 5th digit: 5min longitude slot.
qth += str_chr_lo.charAt(Math.floor((lat % 1) * (60 / 2.5))); // 6th digit: 2.5min latitude slot.
document.getElementById('qth_loc').value = qth; // Display result.
return(0);
}
// --------------------------------------------------------------------------
function cmd_calculate_dec_dms()
{
var lat, lon, qth;
var deg, min, sec;
qth = document.getElementById('qth_loc').value; // Get data from the form.
if ((qth.length != 4) && (qth.length != 6)) // Verify string length: only 4 and 6 character strings are accepted.
{
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('lat_NS').value = "";
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
document.getElementById('qth_loc').value = "";
alert("Please enter a valid 4 or 6 characters QTH locator.");
return(1);
}
qth = qth.toUpperCase(); // Convert to upper case.
if ((qth.charAt(0) < 'A') || (qth.charAt(0) > 'S') || (qth.charAt(1) < 'A') || (qth.charAt(1) > 'S') ||
(qth.charAt(2) < '0') || (qth.charAt(2) > '9') || (qth.charAt(3) < '0') || (qth.charAt(3) > '9'))
{ // Make sure the locator is composed by twho characters and two digits.
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('lat_NS').value = "";
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
document.getElementById('qth_loc').value = "";
alert("Please enter a valid 4 or 6 characters QTH locator.");
return(1);
}
if ((qth.length == 6) && (qth.charAt(4) < 'A') || (qth.charAt(4) > 'X') ||
(qth.charAt(5) < 'A') || (qth.charAt(5) > 'X')) // For 6 characters locators, make sure the last two are letters.
{
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('lat_NS').value = "";
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
document.getElementById('qth_loc').value = "";
alert("Please enter a valid 4 or 6 characters QTH locator.");
return(1);
}
lat = str_chr_up.indexOf(qth.charAt(1)) * 10; // 2nd digit: 10deg latitude slot.
lon = str_chr_up.indexOf(qth.charAt(0)) * 20; // 1st digit: 20deg longitude slot.
lat += str_num.indexOf(qth.charAt(3)) * 1; // 4th digit: 1deg latitude slot.
lon += str_num.indexOf(qth.charAt(2)) * 2; // 3rd digit: 2deg longitude slot.
if (qth.length == 6)
{
lat += str_chr_up.indexOf(qth.charAt(5)) * 2.5 / 60; // 6th digit: 2.5min latitude slot.
lon += str_chr_up.indexOf(qth.charAt(4)) * 5 / 60; // 5th digit: 5min longitude slot.
}
if (qth.length == 4) // Get coordinates of the center of the square.
{
lat += 0.5 * 1;
lon += 0.5 * 2;
}
else
{
lat += 0.5 * 2.5 / 60;
lon += 0.5 * 5 / 60;
}
lat -= 90; // Locator lat/lon origin shift.
lon -= 180;
document.getElementById('lat_dec').value = lat.toFixed(3); // Display result (rounded to 3 decimal digits).
document.getElementById('lon_dec').value = lon.toFixed(3);
deg = Math.floor(Math.abs(lat)); // Convert latitude to deg/min/sec.
min = Math.floor((Math.abs(lat) - deg) * 60);
sec = Math.floor(((Math.abs(lat) - deg) * 60 - min) * 60);
if (lat >= 0)
document.getElementById('lat_NS').value = "N";
else
document.getElementById('lat_NS').value = "S";
document.getElementById('lat_deg').value = deg;
document.getElementById('lat_min').value = (min < 10 ? "0" : "") + min.toString();
document.getElementById('lat_sec').value = (sec < 10 ? "0" : "") + sec.toString();
deg = Math.floor(Math.abs(lon)); // Convert longitude to deg/min/sec.
min = Math.floor((Math.abs(lon) - deg) * 60);
sec = Math.floor(((Math.abs(lon) - deg) * 60 - min) * 60);
if (lon >= 0)
document.getElementById('lon_EW').value = "E";
else
document.getElementById('lon_EW').value = "W";
document.getElementById('lon_deg').value = deg;
document.getElementById('lon_min').value = (min < 10 ? "0" : "") + min.toString();
document.getElementById('lon_sec').value = (sec < 10 ? "0" : "") + sec.toString();
return(0);
}
// --------------------------------------------------------------------------
// Geolocation functions.
// --------------------------------------------------------------------------
// This function, called by the "Get current location" button, will try to
// find the current coordinates, if supported by the browser.
// If the browser supports geolocation, the function show_position() is
// called, if not, show_error() is called instead.
function cmd_get_location()
{
document.getElementById('lat_dec').value = ""; // Erase current coordinates.
document.getElementById('lon_dec').value = "";
document.getElementById('lat_NS').value = ""; // Erase corresponding results.
document.getElementById('lat_deg').value = "";
document.getElementById('lat_min').value = "";
document.getElementById('lat_sec').value = "";
document.getElementById('lon_EW').value = "";
document.getElementById('lon_deg').value = "";
document.getElementById('lon_min').value = "";
document.getElementById('lon_sec').value = "";
document.getElementById('qth_loc').value = "";
if (navigator.geolocation) // Check if geolocation is supported.
navigator.geolocation.getCurrentPosition(show_position, show_error);
else
window.alert("Geolocation is not supported by this browser.");
}
// --------------------------------------------------------------------------
// This function is called by the cmd_get_location() function only if the
// browser supports geolocation. It updates the coordinates field with the
// current position and calculates the coordinate conversion.
function show_position(position)
{
document.getElementById('lat_dec').value = position.coords.latitude.toFixed(6);
document.getElementById('lon_dec').value = position.coords.longitude.toFixed(6);
cmd_calculate_qth_dms();
}
// --------------------------------------------------------------------------
// This function is called by cmd_get_location() when an error occurred while
// determining the current location.
function show_error(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
window.alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
window.alert("Location information is unavailable.");
break;
case error.TIMEOUT:
window.alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
window.alert("An unknown error occurred.");
break;
}
}
// --------------------------------------------------------------------------
// Init form values
document.getElementById('lat_NS').value = "N";
document.getElementById('lat_deg').value = "46";
document.getElementById('lat_min').value = "57";
document.getElementById('lat_sec').value = "04";
document.getElementById('lon_EW').value = "E";
document.getElementById('lon_deg').value = "7";
document.getElementById('lon_min').value = "26";
document.getElementById('lon_sec').value = "19";
document.getElementById('lat_dec').value = "";
document.getElementById('lon_dec').value = "";
document.getElementById('qth_loc').value = "";
// --------------------------------------------------------------------------
// -->
</script>
</body>
</html>
programmieren/amateurfunk/locator.txt · Zuletzt geändert: 06/01/2022 13:45 von conny
