Merge pull request #2972 from HB9HIL/fix_qth_lookup

Fixed QTH Lookup
This commit is contained in:
Fabian Berg
2026-02-19 10:02:18 +01:00
committed by GitHub
3 changed files with 65 additions and 95 deletions

View File

@@ -1270,67 +1270,37 @@ mymap.on('mousemove', onQsoMapMove);
<?php if ($this->session->userdata('user_qth_lookup') == 1) { ?>
$('#qth').focusout(function() {
if ($('#locator').val() === '') {
var lat = 0;
var lon = 0;
$.ajax({
async: false,
type: 'GET',
dataType: "json",
url: "https://nominatim.openstreetmap.org/?city=" + $(this).val() + "&format=json&addressdetails=1&limit=1",
data: {},
success: function (data) {
if (typeof data[0].lat !== 'undefined') {
lat = parseFloat(data[0].lat);
}
if (typeof data[0].lon !== 'undefined') {
lon = parseFloat(data[0].lon);
}
timeout: 5000,
data: {},
success: function (result) {
var data = Array.isArray(result) && result.length > 0 ? result[0] : null;
if (!data) {
return;
}
var lat = parseFloat(data.lat);
var lon = parseFloat(data.lon);
if (isNaN(lat) || isNaN(lon)) {
return;
}
var qthloc = LatLng2Loc(lat, lon, 10);
if (qthloc.length > 0) {
$('#locator').val(qthloc.substr(0, 6)).trigger('input');
}
},
error: function() {
showToast('Error', '<?= __("Location Lookup failed. Please check browser console."); ?>', 'bg-danger text-white', 5000);
},
});
if (lat !== 0 && lon !== 0) {
var qthloc = LatLng2Loc(lat, lon, 10);
if (qthloc.length > 0) {
$('#locator').val(qthloc.substr(0, 6)).trigger('focusout');
}
}
}
});
LatLng2Loc = function(y, x, num) {
if (x < -180) {
x = x + 360;
}
if (x > 180) {
x = x - 360;
}
var yqth, yi, yk, ydiv, yres, ylp, y;
var ycalc = new Array(0, 0, 0);
var yn = new Array(0, 0, 0, 0, 0, 0, 0);
var ydiv_arr = new Array(10, 1, 1 / 24, 1 / 240, 1 / 240 / 24);
ycalc[0] = (x + 180) / 2;
ycalc[1] = y + 90;
for (yi = 0; yi < 2; yi++) {
for (yk = 0; yk < 5; yk++) {
ydiv = ydiv_arr[yk];
yres = ycalc[yi] / ydiv;
ycalc[yi] = yres;
if (ycalc[yi] > 0) ylp = Math.floor(yres); else ylp = Math.ceil(yres);
ycalc[yi] = (ycalc[yi] - ylp) * ydiv;
yn[2 * yk + yi] = ylp;
}
}
var qthloc = "";
if (num >= 2) qthloc += String.fromCharCode(yn[0] + 0x41) + String.fromCharCode(yn[1] + 0x41);
if (num >= 4) qthloc += String.fromCharCode(yn[2] + 0x30) + String.fromCharCode(yn[3] + 0x30);
if (num >= 6) qthloc += String.fromCharCode(yn[4] + 0x41) + String.fromCharCode(yn[5] + 0x41);
if (num >= 8) qthloc += ' ' + String.fromCharCode(yn[6] + 0x30) + String.fromCharCode(yn[7] + 0x30);
if (num >= 10) qthloc += String.fromCharCode(yn[8] + 0x61) + String.fromCharCode(yn[9] + 0x61);
return qthloc;
}
<?php } ?>
<?php } ?>
</script>