Giter Club home page Giter Club logo

geohash's Introduction

geohash

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

geohash能做到 @一个开发者

paypaldonate

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
)
  • 范围如图:

  • 用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多万行测试数据):

索引:

数据:

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

其他资料:

geohash's People

Contributors

cloudside avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geohash's Issues

Uninitialized string offset: -1

PHP Notice: Uninitialized string offset: -1 in /home/server/gochat/geohash.class.php on line 110
PHP Warning: strpos(): Empty needle in /home/server/gochat/geohash.class.php on line 114
PHP Warning: strpos(): Empty needle in /home/server/gochat/geohash.class.php on line 119
PHP Notice: String offset cast occurred in /home/server/gochat/geohash.class.php on line 119

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.