Author: Keisuke SATO
Example #1
0
 /**
  * 根据前端的商铺坐标信息获取商铺数据
  **/
 public function shopsGet()
 {
     $locations = Input::get('restaurant');
     //        $locations = json_decode($locations);
     if (empty($locations) || !is_array($locations)) {
         echo json_encode(array('success' => false, 'state' => 200, 'errMsg' => '坐标数据为空', 'data' => ''));
         exit;
     }
     $shopData = array();
     $geoHash = new Geohash();
     foreach ($locations as $key => $value) {
         array_push($shopData, $geoHash->getAmount($value['1'], $value['0']));
     }
     echo json_encode(array('success' => true, 'state' => 200, 'errMsg' => '', 'data' => $shopData));
 }
Example #2
0
 /**
  * test cases for adjacent geohashes.
  */
 function testAdjacent()
 {
     $geohash = new Geohash();
     $this->assertEquals('xne', $geohash->adjacent('xn7', 'top'), 'Did not find correct top adjacent geohash for xn7');
     $this->assertEquals('xnk', $geohash->adjacent('xn7', 'right'), 'Did not find correct right adjacent geohash for xn7');
     $this->assertEquals('xn5', $geohash->adjacent('xn7', 'bottom'), 'Did not find correct bottom adjacent geohash for xn7');
     $this->assertEquals('xn6', $geohash->adjacent('xn7', 'left'), 'Did not find correct left adjacent geohash for xn7');
     $this->assertEquals('xnd', $geohash->adjacent($geohash->adjacent('xn7', 'left'), 'top'), 'Did not find correct top-left adjacent geohash for xn7');
 }
Example #3
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";
 public function geoHashGet()
 {
     $geohash = new Geohash();
     /*
      **此处参数对应经纬度
      **返回值为数组,status标识同上
      **data对应查到的数据,若不为空,data数组内,geohash对应geohash表的坐标及geohash信息,shop对应shop表里面的店铺数据
      */
     $get = $geohash->geohashGet(39.98123662, 116.3068369);
     var_dump($get);
 }
Example #5
0
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * 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]} : ";
Example #6
0
 /**
  * 获取某个店铺的基本信息
  */
 public function getShopInfo($shop_id)
 {
     $shop = Shop::find($shop_id);
     $info = array();
     $info['shop_id'] = $shop_id;
     // 商家ID
     #TODO:place_id不需要
     $info['shop_logo'] = $shop->pic;
     // 商家的logo图片地址
     $info['shop_name'] = $shop->name;
     // 商家名称
     $info['shop_type'] = $shop->type;
     // 商家类型,逗号分隔的字符串
     $Level = $this->getLevel($shop);
     $info['shop_level'] = $Level['thing_level'];
     // 总共10个等级
     $info['shop_total'] = $Level['thing_total'];
     // 总评价
     $info['comment_count'] = $Level['comment_count'];
     // 评论人数
     $info['shop_statement'] = $shop->intro;
     // 商家简介
     $info['shop_time'] = $shop->operation_time;
     // 营业时间,字符串表示
     $info['shop_address'] = $shop->address;
     // 商家地址
     $info['deliver_begin'] = $shop->begin_time;
     // 送餐开始时间
     $xy = Geohash::find($shop_id);
     #TODO:前端给出用户的经纬度
     $user_x = 39.98123;
     $user_y = 116.3068369;
     $info['shop_distance'] = $this->getDistance($xy->x, $xy->y, $user_x, $user_y);
     // 人与店铺的距离(米)
     $info['price_begin'] = (double) $shop->deliver_price;
     // 起送价
     if (Auth::check()) {
         $front_user = Auth::user();
         $info['is_collected'] = in_array($shop_id, $front_user->collectShop->lists('shop_id')) ? 'true' : 'false';
         // 是否被收藏了
     } else {
         $info['is_collected'] = 'false';
     }
     #TODO:右上角的送货速度,董天成添加这个API
     $info['interval'] = $shop->interval;
     // 送餐速度
     #TODO:shop_remark API里两个不同的top_bar
     $info['shop_remark'] = '';
     return $info;
 }
Example #7
0
         }
     }
     //截取接到位置
     $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}' ");
     }
 }
$area_2 = Geohash::getInstance()->fastDecode($hashbit_2);
echo "Geohash::fastDecode($hashbit_2):\n";
var_dump($area_2);

$neighbors = Geohash::getInstance()->neighbors($hashbit_1, 24);
echo "Geohash::neighbors($hashbit_1, 24):\n";
var_dump($neighbors);

// program mark - real search test 52.53261	
$steps = Geohash::getInstance()->stepInRadius(10000);
echo "Geohash::stepInRadius(10000) : ".($steps)."\n";

$hashbit = Geohash::getInstance()->encode(52.53261, 13.3777, $steps);
$hashbit_1 = $hashbit + 1;
echo "Geohash::encode(52.53261, 13.3777, $steps) : ".($hashbit)."\n";
echo "$hashbit + 1 : ".($hashbit_1)."\n";

$hashbit_shift = $hashbit << (52-$steps*2);
$hashbit_1_shift = $hashbit_1 << (52-$steps*2);
echo "$hashbit << (52-$steps*2) : ".($hashbit_shift)."\n";
echo "$hashbit_1 << (52-$steps*2) : ".($hashbit_1_shift)."\n";

$ret = Geohash::getInstance()->radiusSearch(52.53261, 13.3777, 10000, true);
var_dump($ret);

$hashbit_2 = Geohash::getInstance()->encode(52.53261, 13.3777);
echo "Geohash::encode(52.53261, 13.3777) : ".($hashbit_2)."\n";


Example #9
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);
Example #10
0
 /**
  * 获取餐厅列表
  * 默认15个,多的在更多餐厅里面显示
  */
 public function getShopList($user_x, $user_y)
 {
     $result = array('shop_list' => array(), 'more_shop' => array());
     $result['shop_list']['data'] = array();
     $result['more_shop']['data'] = array();
     $result['shop_list']['data']['shops'] = array();
     # 首先获取所有的活动
     $result['shop_list']['data']['activity'] = array();
     $activity = Activity::all();
     foreach ($activity as $act) {
         if ($act->aid != '1') {
             $result['shop_list']['data']['activity'][(string) $act->aid] = $act->name;
         }
     }
     $data['shops'] = array();
     $geohash = new Geohash();
     $shopArray = $geohash->geohashGet($user_x, $user_y);
     $shops = $shopArray['data'];
     $num = 0;
     // 计数器,只15个
     foreach ($shops as $oneshop) {
         $onestore = array();
         $shop = $oneshop['shopData'];
         $support_activity = explode(',', $shop->support_activity);
         $onestore['support_activity'] = $support_activity[0] == '' ? [] : $support_activity;
         // 所有支持的活动id
         $onestore['isHot'] = $shop->is_hot ? 'true' : 'false';
         // 是否是热门餐厅
         $onestore['isOnline'] = $this->isOnline($shop->operation_time, date('H:i')) ? true : false;
         // 是否营业
         $onestore['isSupportPay'] = in_array('1', explode(',', $shop->pay_method));
         // 是否支持在线支付
         $onestore['shop_id'] = $shop->id;
         // 商家id
         $onestore['place_id'] = 111111;
         // -------------------位置经纬度和位置id后期再改数据库
         $onestore['shop_url'] = url('shop/' . $shop->id);
         // 点击跳转到相应商家
         $onestore['shop_logo'] = $shop->pic;
         // 商家的logo图片地址
         $onestore['deliver_time'] = (double) $shop->interval;
         // 送货时间间隔
         $onestore['deliver_start'] = $shop->begin_time;
         // 送货开始时间
         $onestore['shop_name'] = $shop->name;
         // 商家名称
         /*
         echo $onestore['isOnline'];
         echo $onestore['shop_name'];
         */
         $onestore['shop_type'] = $shop->type;
         $Level = $this->getLevel($shop);
         $onestore['shop_level'] = $Level['thing_total'];
         // 五分制
         $onestore['shop_announce'] = $shop->announcement;
         // 商家公告
         $onestore['deliver_state_start'] = $shop->begin_price;
         $onestore['deliver_start_statement'] = $shop->begin_price;
         // 起送价描述
         $onestore['shop_address'] = $shop->address;
         // 商家地址
         $onestore['is_opening'] = $this->isOnline($shop->operation_time, date('H:i')) ? 0 : 1;
         // 0是正在营业,1是打烊了,2是太忙了
         $onestore['is_ready_for_order'] = $shop->reserve;
         // 是否接收预定
         $onestore['close_msg'] = $shop->close_msg;
         // 关门信息
         $onestore['business_hours'] = $shop->operation_time;
         // 营业时间
         $onestore['shop_summary'] = $shop->intro;
         // 商家简介
         $onestore['order_count'] = (double) $shop->sold_num;
         // 订单数量
         if (!Auth::check()) {
             $onestore['is_collected'] = false;
         } else {
             $user = Auth::user();
             $onestore['is_collected'] = in_array($shop->id, $user->collectShop->lists('shop_id')) ? true : false;
             // 是否被收藏了
         }
         $onestore['additions'] = array();
         // 额外的内容
         $num = $num + 1;
         if ($num < 4) {
             // 更多餐厅和上面那排餐厅的数量
             array_push($result['shop_list']['data']['shops'], $onestore);
         } else {
             array_push($result['more_shop']['data'], $onestore);
         }
     }
     return $result;
 }
Example #11
0
 /**
  * 获取餐厅列表
  * 默认15个,多的在更多餐厅里面显示
  */
 public function getShopList()
 {
     $result = array('shop_list' => array(), 'more_shop' => array());
     $result['shop_list']['data'] = array();
     $result['more_shop']['data'] = array();
     $result['shop_list']['data']['shops'] = array();
     # 首先获取所有的活动
     $result['shop_list']['data']['activity'] = array();
     $activity = Activity::all();
     foreach ($activity as $act) {
         $result['shop_list']['data']['activity'][(string) $act->aid] = $act->name;
     }
     $data['shops'] = array();
     #TODO:由前端获取用户坐标
     $user_x = 39.9812385;
     $user_y = 116.3068369;
     $geohash = new Geohash();
     $shopArray = $geohash->geohashGet($user_x, $user_y);
     $shops = $shopArray['data'];
     #TODO:这个地方的$shops就应该进缓存了
     $num = 0;
     // 计数器,只15个
     foreach ($shops as $oneshop) {
         $onestore = array();
         $shop = $oneshop['shopData'];
         $onestore['support_activity'] = explode(',', $shop->support_activity);
         // 所有支持的活动id
         $onestore['isHot'] = $shop->is_hot ? 'true' : 'false';
         // 是否是热门餐厅
         $onestore['isOnline'] = $shop->is_online ? 'true' : 'false';
         // 是否营业
         $onestore['isSupportPay'] = in_array('1', explode(',', $shop->pay_method));
         // 是否支持在线支付
         $onestore['shop_id'] = $shop->id;
         // 商家id
         #TODO:place_id不需要
         $onestore['place_id'] = '不需要';
         // -------------------位置经纬度和位置id后期再改数据库
         $onestore['shop_url'] = 'shop/' . $shop->id;
         // 点击跳转到相应商家
         $onestore['shop_logo'] = $shop->pic;
         // 商家的logo图片地址
         $onestore['deliver_time'] = $shop->interval;
         // 送货时间间隔
         $onestore['deliver_start'] = $shop->begin_time;
         // 送货开始时间
         $onestore['shop_name'] = $shop->name;
         // 商家名称
         $onestore['shop_type'] = $shop->type;
         $Level = $this->getLevel($shop);
         $onestore['shop_level'] = $Level['thing_total'];
         // 五分制
         $onestore['shop_announce'] = $shop->announcement;
         // 商家公告
         #TODO:模版里用的deliver_state_start
         $onestore['deliver_state_start'] = $shop->begin_price;
         $onestore['deliver_start_statement'] = $shop->begin_price;
         // 起送价描述
         $onestore['shop_address'] = $shop->address;
         // 商家地址
         $onestore['is_opening'] = $shop->state;
         // 0是正在营业,1是打烊了,2是太忙了
         $onestore['is_ready_for_order'] = $shop->reserve;
         // 是否接收预定
         $onestore['close_msg'] = $shop->close_msg;
         // 关门信息
         $onestore['business_hours'] = $shop->operation_time;
         // 营业时间
         $onestore['shop_summary'] = $shop->intro;
         // 商家简介
         $onestore['order_count'] = $shop->sold_num;
         // 订单数量
         if (!Auth::check()) {
             $onestore['is_collected'] = false;
         } else {
             $user = Auth::user();
             $onestore['is_collected'] = in_array($shop->id, $user->collectShop->lists('shop_id')) ? true : false;
             // 是否被收藏了
         }
         #TODO:额外内容有什么用
         $onestore['additions'] = array();
         // 额外的内容
         $num = $num + 1;
         if ($num < 2) {
             array_push($result['shop_list']['data']['shops'], $onestore);
         } else {
             array_push($result['more_shop']['data'], $onestore);
         }
     }
     return $result;
 }