Added what3words.com support in coordinates output. API key was
registered for Opencaching.de.
This commit is contained in:
parent
cfd22c14ce
commit
ad039dd69b
@ -30,6 +30,8 @@
|
||||
$tpl->assign('showRD', ($coord->nLat >= 45 && $coord->nLat <= 57 && $coord->nLon >= 0 && $coord->nLon <= 15));
|
||||
$tpl->assign('coordQTH', $coord->getQTH());
|
||||
$tpl->assign('coordSwissGrid', $coord->getSwissGrid());
|
||||
$tpl->assign('coordW3Wde', $coord->getW3W('de'));
|
||||
$tpl->assign('coordW3Wen', $coord->getW3W('en'));
|
||||
|
||||
// wp gesetzt?
|
||||
$wp = isset($_REQUEST['wp']) ? $_REQUEST['wp'] : '';
|
||||
|
@ -9,6 +9,7 @@ class coordinate
|
||||
{
|
||||
var $nLat = 0;
|
||||
var $nLon = 0;
|
||||
var $w3wApiKey = 'MVPP32BC'; // what3words.com
|
||||
|
||||
function __construct($nNewLat, $nNewLon)
|
||||
{
|
||||
@ -553,5 +554,30 @@ class coordinate
|
||||
|
||||
return $lon;
|
||||
}
|
||||
|
||||
function getW3W($language = "de")
|
||||
{
|
||||
$params = array(
|
||||
'key' => $this->w3wApiKey,
|
||||
'position' => sprintf('%f,%f', $this->nLat, $this->nLon),
|
||||
'lang' => $language,
|
||||
);
|
||||
$params_str = http_build_query($params);
|
||||
$context = stream_context_create( array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/x-www-form-urlencoded\r\n" .
|
||||
"Content-Length: " . strlen($params_str) . "\r\n",
|
||||
'content' => $params_str,
|
||||
),
|
||||
));
|
||||
|
||||
$result = file_get_contents('http://api.what3words.com/position', false, $context);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
$json = json_decode($result, true);
|
||||
return implode('.', $json['words']);
|
||||
}
|
||||
}
|
||||
?>
|
@ -45,3 +45,11 @@
|
||||
{$coordRD|escape}</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div style="margin-top:4px;">
|
||||
<p style="color: 5890a8"><b>what3words</b> <small>(deutsch)</small><br />
|
||||
{$coordW3Wde|escape}</p>
|
||||
</div>
|
||||
<div style="margin-top:4px;">
|
||||
<p style="color: 5890a8"><b>what3words</b> <small>(english)</small><br />
|
||||
{$coordW3Wen|escape}</p>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user