首页 > Web开发 > 详细

PHP之路——geohash查找附近的人

时间:2017-06-07 13:26:30      阅读:534      评论:0      收藏:0      [点我收藏+]
<?php
	
class location
{
	public function getLat($number, $small, $big,  $temp = 20){
		$temp--;
		$average = ($big + $small) / 2;
		if ($temp == 0) {
			if ($average <= $number) {
				return ‘1‘;
			} else {
				return ‘0‘;
			}
		}
		if ($average <= $number) {
			return ‘1‘ . $this->getLat($number, $average, $big, $temp);
		} else {
			return ‘0‘ . $this->getLat($number, $small, $average, $temp);
		}
	}

	public function joinStr($lat, $lon){
		$len = strlen($lat);
		$str = ‘‘;
		for ($i=0; $i < $len; $i++) { 
			$str .= $lon[$i] . $lat[$i];
		}
		return $str;
	}
}

$location = new location();
$lat = $location->getLat(39.92324, -90, 90);
$lon = $location->getLat(116.3906, -180, 180);
$str =  $location->joinStr($lat, $lon);
for ($i=0; $i <strlen($str) / 5 ; $i++) { 
	$code[$i] = bindec(substr($str, $i * 5, 5));
}
foreach ($code as $key => $value) {
	echo $value . "\n";
}

  

PHP之路——geohash查找附近的人

原文:http://www.cnblogs.com/xj76149095/p/6956266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!