encode() 공개 메소드

Encode a hash from given lat and long
public encode ( $lat, $long )
예제 #1
0
<?php

error_reporting(E_ALL);
echo "version:" . GEOHASH_VERSION . "\n";
echo microtime(true) . "\n";
$geohash = "wm3yr31d2524";
$coord = Geohash::decode($geohash);
print_r($coord);
var_dump($geohash, $coord);
$geohash = Geohash::encode($coord['latitude'], $coord['longitude']);
print_r(Geohash::encode(30.635780068114, 104.03160111979, 12));
var_dump($geohash);
echo microtime(true) . "\n";
예제 #2
0
파일: zaina.php 프로젝트: Huangzefeng/zaina
     //截取接到位置
     $jiedao = preg_replace('/^([^\\d]+).*/', '$1', $jiedao);
     //从缓存服务器获取该用户上次的地点
     //并且判断是否是一个地点提交的数据
     $mem = new Memcache();
     $mem->connect("127.0.0.1", 11211);
     $userjiedao = $mem->get($umd5 . 'jiedao');
     if ($userjiedao != $jiedao) {
         //如果不是则插入数据库
         /*******************获取该人的geohash********************/
         $jwdarrtmp = explode(',', $jingweidu);
         //include('./lib/geohash.class.php');
         require_once './lib/geohash.class.php';
         $geohash = new Geohash();
         //得到这点的hash值
         $hash = $geohash->encode($jwdarrtmp[1], $jwdarrtmp[0]);
         // echo $hash;
         //取前缀,前缀约长范围越小
         //$prefix = substr($hash, 0, 5);
         //取出相邻八个区域
         //$neighbors = $geohash->neighbors($prefix);
         /***************************************/
         $insert = array('geo' => $jingweidu, 'time' => time(), 'ip' => $_SERVER["REMOTE_ADDR"], 'jiedao' => safeEncoding($jiedao), 'geohash' => $hash, 'umd5' => $umd5);
         $mem->set($umd5 . 'jiedao', $jiedao, 0, 600);
         $db->row_insert("zaina", $insert);
         $update = array('zaina' => $jiedao, 'version' => $version);
         $db->row_update('user', $update, " umd5 = '{$umd5}' ");
     }
 }
 //	SELECT zaina.time ,zaina.jiedao,zaina.umd5,`user`.age ,`user`.sex ,`user`.headurl ,`user`.`name` FROM zaina LEFT JOIN `user` ON (zaina.umd5=`user`.umd5)WHERE zaina.time > 1408204280
 //这里请求每隔一段时间缓存一次(缓存在文件中)分页 时间
예제 #3
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geohash.class.php';
$geohash = new Geohash();
//these test hashes were made on geohash.org
//and test various combinations of precision
//and range
$tests = array("ezs42" => array(42.6, -5.6), "mh7w" => array(-20, 50), "t3b9m" => array(10.1, 57.2), "c2b25ps" => array(49.26, -123.26), "80021bgm" => array(0.005, -179.567), "k484ht99h2" => array(-30.55555, 0.2), "8buh2w4pnt" => array(5.00001, -140.6));
foreach ($tests as $actualhash => $coords) {
    $computed_hash = $geohash->encode($coords[0], $coords[1]);
    echo "Encode {$coords[0]}, {$coords[1]} as {$actualhash} : ";
    if ($computed_hash == $actualhash) {
        echo "OK<br>";
    } else {
        echo "FAIL (got {$computed_hash})<br>";
    }
    echo "<hr>";
    $computed_coords = $geohash->decode($actualhash);
    echo "Decode {$actualhash} as {$coords[0]}, {$coords[1]} : ";
    if ($computed_coords[0] == $coords[0] && $computed_coords[1] == $coords[1]) {
        echo "OK<br>";
    } else {
        echo "FAIL (got {$computed_coords[0]}, {$computed_coords[1]})<br>";
    }
    echo "<hr>";
예제 #4
0
<?php

/**
 * Geohash generation class for php - test
 *
 * This file copyright (C) 2013 Bruce Chen (http://weibo.com/smcz)
 *
 * Author: Bruce Chen (weibo: @一个开发者)
 *
 */
require_once 'geohash.class.php';
$geohash = new Geohash();
//得到这点的hash值
$hash = $geohash->encode(39.98123848, 116.3068369);
//取前缀,前缀约长范围越小
$prefix = substr($hash, 0, 6);
//取出相邻八个区域
$neighbors = $geohash->neighbors($prefix);
array_push($neighbors, $prefix);
print_r($neighbors);