PHP code example of xianyunyh / geohash

1. Go to this page and download the library: Download xianyunyh/geohash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xianyunyh / geohash example snippets



$geohash = new Geohash;
//得到这点的hash值
$hash = $geohash->encode(39.98123848, 116.30683690);
//取前缀,前缀约长范围越小
$prefix = substr($hash, 0, 6);
//取出相邻八个区域
$neighbors = $geohash->neighbors($prefix);
array_push($neighbors, $prefix);

print_r($neighbors);



//得到9个geohash值

Array
(
    [top] => wx4eqx
    [bottom] => wx4eqt
    [right] => wx4eqy
    [left] => wx4eqq
    [topleft] => wx4eqr
    [topright] => wx4eqz
    [bottomright] => wx4eqv
    [bottomleft] => wx4eqm
    [0] => wx4eqw
)