Skip to content
Permalink
Browse files

Added what3words.com support in coordinates output. API key was

registered for Opencaching.de.
  • Loading branch information...
mbirth committed Jan 12, 2015
1 parent cfd22c1 commit ad039dd69b904cfbd087a6eb6717ac655f482147
Showing with 36 additions and 0 deletions.
  1. +2 −0 htdocs/coordinates.php
  2. +26 −0 htdocs/lib2/logic/coordinate.class.php
  3. +8 −0 htdocs/templates2/ocstyle/coordinates.tpl
@@ -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 @@ static function parseRequestLon($name)
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>

0 comments on commit ad039dd

Please sign in to comment.
You can’t perform that action at this time.