Looking to hire Laravel developers? Try LaraJobs

laravel-geohash maintained by ethan

Description
Implementation of geohash's laravel extension package
Author
Last update
2019/08/22 11:36 (dev-master)
License
Links
Downloads
55 143

Comments
comments powered by Disqus

Laravel GeoHash

Laravel GeoHash LBS地理位置距离计算方法geohash,将一个经纬度信息,转换成一个可以排序,可以比较的字符串编码,用于高效搜索

安装方法

composer require ethanfly/laravel-geohash

使用方法

<?php

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值
    }
}