PHP code example of ethan / laravel-geohash

1. Go to this page and download the library: Download ethan/laravel-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/ */

    

ethan / laravel-geohash example snippets


composer 



namespace App\Http\Controllers;

use GeoHash;
class IndexController extends Controller
{
    public function index()
    {
        // 参数:纬度,经度,长度(可选,默认为最长)
        $geo = GeoHash::encode("69.3252", "136.2345", 9);
        echo $geo;
        
        list($lat, $lng) = GeoHash::decode($geo);
        echo $lat, ', ', $lng;
        //获取附近的8个格子
        //取出相邻八个区域包括自己
        $neighbors = GeoHash::neighbors($geo);
        //获取两点距离
        $distance=GeoHash::GetDistanceByPoint($lat1,$lng1,$lat2,$lng2);//两点经纬度
        $distance=GeoHash::GetDistanceByHash($hash1,$hash2);//两点hash值
    }
}