From 8365b17f7cb2cc5b70740ca2a647f024f6e491b2 Mon Sep 17 00:00:00 2001 From: Kim Huebel Date: Mon, 24 Jun 2019 15:57:48 +0200 Subject: [PATCH] Enable configuring the measurement base distance is measured in --- application/config/cloudlog.php | 18 +++++++++++++++++- application/controllers/Logbook.php | 10 +++++----- application/libraries/Qra.php | 21 ++++++++++++++++----- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/application/config/cloudlog.php b/application/config/cloudlog.php index aa128665..b1209ad7 100644 --- a/application/config/cloudlog.php +++ b/application/config/cloudlog.php @@ -16,4 +16,20 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | and on QSO-detail-view, set this to TRUE, otherwise set it to FALSE | */ -$config['show_time'] = FALSE; \ No newline at end of file +$config['show_time'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Configure the measurement base distance is measured in +|-------------------------------------------------------------------------- +| +| Here you can configure different measurement bases to be used on +| distance caculations. Valid values are: +| M: miles +| K: kilometers +| N: nautic miles +| +| Default is: M +| +*/ +$config['measurement_base'] = 'M'; \ No newline at end of file diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index d43bed4d..a6a8cf3f 100755 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -88,7 +88,7 @@ class Logbook extends CI_Controller { $return['callsign_qth'] = $this->logbook_model->call_qth($callsign); $return['callsign_iota'] = $this->logbook_model->call_iota($callsign); $return['qsl_manager'] = $this->logbook_model->call_qslvia($callsign); - $return['bearing'] = $this->bearing($return['callsign_qra']); + $return['bearing'] = $this->bearing($return['callsign_qra'], $this->config->item('measurement_base')); $return['workedBefore'] = $this->worked_grid_before($return['callsign_qra']); if ($return['callsign_qra'] != "") { @@ -139,7 +139,7 @@ class Logbook extends CI_Controller { } $return['workedBefore'] = $this->worked_grid_before($return['callsign_qra']); } - $return['bearing'] = $this->bearing($return['callsign_qra']); + $return['bearing'] = $this->bearing($return['callsign_qra'], $this->config->item('measurement_base')); echo json_encode($return, JSON_PRETTY_PRINT); @@ -383,7 +383,7 @@ class Logbook extends CI_Controller { $mylocator = $this->config->item('locator'); } - $bearing = $this->qra->bearing($mylocator, $locator); + $bearing = $this->qra->bearing($mylocator, $locator, $this->config->item('measurement_base')); echo $bearing; } @@ -391,7 +391,7 @@ class Logbook extends CI_Controller { } /* return station bearing */ - function bearing($locator) { + function bearing($locator, $unit = 'M') { $this->load->library('Qra'); @@ -404,7 +404,7 @@ class Logbook extends CI_Controller { - $bearing = $this->qra->bearing($mylocator, $locator); + $bearing = $this->qra->bearing($mylocator, $locator, $unit); return $bearing; } diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index 62ea3b6a..4f6d869e 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -10,11 +10,11 @@ class Qra { return qra2latlong($strQRA); } - function bearing($tx, $rx) { + function bearing($tx, $rx, $unit = 'M') { $my = qra2latlong($tx); $stn = qra2latlong($rx); - $bearing = bearing($my[0], $my[1], $stn[0], $stn[1]); + $bearing = bearing($my[0], $my[1], $stn[0], $stn[1], $unit); return $bearing; } @@ -37,7 +37,7 @@ cos(deg2rad($theta)); return round($dist, 1); } -function bearing($lat1, $lon1, $lat2, $lon2) { +function bearing($lat1, $lon1, $lat2, $lon2, $unit = 'M') { if (round($lon1, 1) == round($lon2, 1)) { if ($lat1 < $lat2) { $bearing = 0; @@ -45,7 +45,7 @@ function bearing($lat1, $lon1, $lat2, $lon2) { $bearing = 180; } } else { - $dist = distance($lat1, $lon1, $lat2, $lon2, 'N'); + $dist = distance($lat1, $lon1, $lat2, $lon2, $unit); $arad = acos((sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($lat1)))); $bearing = $arad * 180 / pi(); @@ -68,7 +68,18 @@ function bearing($lat1, $lon1, $lat2, $lon2) { $var_dist = ""; #return $dir; if (isset($dist)) { - $var_dist = $dist." miles"; + $var_dist = $dist; + switch ($unit) { + case 'M': + $var_dist .= " miles"; + break; + case 'N': + $var_dist .= " nautic miles"; + break; + case 'K': + $var_dist .= " kilometers"; + break; + } } return round($bearing, 0)."º ".$dir." ".$var_dist; }