Skip to content
Permalink
Browse files

added what3words coordinat search to map

  • Loading branch information...
following5 committed May 24, 2015
1 parent 89d4645 commit 40511db4abe1ff98ee65f84220d4c5fe2dc529c9
Showing with 36 additions and 5 deletions.
  1. +22 −5 htdocs/map2.php
  2. +14 −0 htdocs/templates2/ocstyle/map2.tpl
@@ -375,9 +375,7 @@ function output_cachexml($sWaypoint)
function output_namesearch($sName, $nLat, $nLon, $nResultId)
{
global $login;
$sName = '%' . $sName . '%';
global $login, $opt;
echo '<caches>' . "\n";
$rs = sql_slave("SELECT " . geomath::getSqlDistanceFormula($nLon, $nLat, 0) . " AS `distance`,
@@ -389,15 +387,34 @@ function output_namesearch($sName, $nLat, $nLon, $nResultId)
AND (`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`='&3')
AND `map2_data`.`result_id`='&2'
ORDER BY `distance` ASC LIMIT 30",
$sName,
'%' . $sName . '%',
$nResultId,
$login->userid);
$caches_found = 0;
while ($r = sql_fetch_assoc($rs))
{
echo '<cache name="' . xmlentities($r['name']) . '" wpoc="' . xmlentities($r['wp_oc']) . '" />' . "\n";
++$caches_found;
}
sql_free_result($rs);
echo '</caches>';
if (!$caches_found && preg_match('/^[^\s]{2,}\.[^\s]{2,}\.[^\s]{2,}$/', $sName))
{
$result = @file_get_contents('http://api.what3words.com/w3w?key=' . $opt['lib']['w3w']['apikey']
. '&string=' . urlencode($sName));
if ($result)
{
$json = json_decode($result, true);
if (!is_null($json['words']) && !is_null($json['position']) && count($json['position']) == 2)
{
echo '<coord name="' . xmlentities(implode('.', $json['words'])) .
'" latitude="' . xmlentities($json["position"][0]) .
'" longitude="' . xmlentities($json["position"][1]) . '" />' ."\n";
}
}
}
echo '</caches>' . "\n";
exit;
}
@@ -1749,6 +1749,20 @@ function mapsearch_click()
}
}
if (moSearchList.length==0)
{
var coords = xml.documentElement.getElementsByTagName("coord");
for (var nCoordIndex=0; nCoordIndex<coords.length; nCoordIndex++)
{
var value = add_searchlist_itemcoords(coords[nCoordIndex].getAttribute("latitude"),
coords[nCoordIndex].getAttribute("longitude"),
"",
coords[nCoordIndex].getAttribute("name"));
var item = new Option(coords[nCoordIndex].getAttribute("name"), value);
moSearchList.options[moSearchList.length] = item;
}
}
if (moSearchList.length==0)
{
mapselectlist_hide();

0 comments on commit 40511db

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