Laravel-GeoHash LBS地理位置距离计算方法geo

2018-06-26  本文已影响0人  YouthAge

Laravel GeoHash

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

安装方法

composer require youthage/laravel-geohash

配置方法

app.php 配置如下:

providers中添加

Geohash\GeoHashProvider::class,

aliases中添加

'GeoHash' => \Geohash\GeoHashFacade::class,

使用方法

<?php

namespace App\Http\Controllers;

use GeoHash;
class IndexController extends Controller
{
    public function index()
    {
        // 参数:纬度,经度
        $geo = GeoHash::encode("69.3252", "136.2345");
        echo $geo;

        list($lat, $lng) = GeoHash::decode($geo);
        echo $lat, ', ', $lng;
    }
}

上一篇 下一篇

猜你喜欢

热点阅读