2017 © Pedro Peláez
 

library geohash

xianyunyehe/geohash

image

xianyunyh/geohash

xianyunyehe/geohash

  • Friday, May 26, 2017
  • by tianlei
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 91 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

geohash

这年头和LBS相关的应用越来越火. 从foursquare的热闹程度就可见一般, 更不用说微信、陌陌了 (什么, 没听过 foursquare... 哥们, 你 out 了). 和 LBS有关的应用一般都包括一些共同的操作, 最常见的一个, 就是找附近的东东(餐馆, 商店, 妞....). 所以, 这里就抛出了一个问题, 怎样才能在大量经纬度数据中检索出附近的点呢?, (*1)

geohash能做到 @一个开发者, (*2)

, (*3)

paypaldonate, (*4)

, (*5)

Requirements

  • PHP >= 4

Usage

  • 例如: 用iPhone/android手机定位得到理想国际大厦的经纬度: 39.98123848, 116.30683690 然后查找附近的妞

require_once('geohash.class.php'); $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值

//得到9个geohash值 Array ( [top] => wx4eqx [bottom] => wx4eqt [right] => wx4eqy [left] => wx4eqq [topleft] => wx4eqr [topright] => wx4eqz [bottomright] => wx4eqv [bottomleft] => wx4eqm [0] => wx4eqw )
  • 范围如图:

, (*6)

  • 用sql语句查询
SELECT * FROM xy WHERE geohash LIKE 'wx4eqw%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqx%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqt%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqy%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqq%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqr%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqz%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqv%';
SELECT * FROM xy WHERE geohash LIKE 'wx4eqm%';
  • 看一下是否用上索引 (一共有50多万行测试数据):

索引:, (*7)

, (*8)

数据:, (*9)

, (*10)

EXPLAIN SELECT * FROM xy WHERE geohash LIKE 'wx4eqw%';

, (*11)

其他资料: - geohash演示: http://openlocation.org/geohash/geohash-js/ - wiki: http://en.wikipedia.org/wiki/Geohash - 原理: https://github.com/CloudSide/geohash/wiki, (*12)

The Versions

26/05 2017

dev-master

9999999-dev

xianyunyehe/geohash

  Sources   Download

BSD

The Requires

  • php ^5.3.3 || ^7.0

 

by xianyun

21/05 2017

1.0.0

1.0.0.0

xianyunyehe/geohash

  Sources   Download

BSD

The Requires

  • php ^5.3.3 || ^7.0

 

by xianyun