ethan/laravel-geohash

Implementation of geohash's laravel extension package

v1.0.7 2019-08-22 09:36 UTC

This package is auto-updated.

Last update: 2024-04-22 20:58:25 UTC


README

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