TestGeohash.php 842 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2018/4/2
  6. * Time: 下午4:13
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/core/framework/libraries/geohash.php');
  11. class TestGeohash extends PHPUnit_Framework_TestCase
  12. {
  13. public static function setUpBeforeClass()
  14. {
  15. Base::run_util();
  16. }
  17. public function testAll()
  18. {
  19. $geohash = new geohash;
  20. //得到这点的hash值
  21. $hash = $geohash->encode(39.98123848, 116.30683690);
  22. //取前缀,前缀约长范围越小
  23. $prefix = substr($hash, 0, 6);
  24. //取出相邻八个区域
  25. $neighbors = $geohash->neighbors($prefix);
  26. array_push($neighbors, $prefix);
  27. print_r($neighbors);
  28. }
  29. }