TestGeohash.php 1007 B

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