Git Product home page Git Product logo

geohash's Introduction

Geohash

Geohash is a php module that provides below functions.

  • Encoding geographic location into short string of letters and digits.
  • Decoding string of letters and digits to latitude and longitude.
  • Identifying the neighbouring geohashes of a provided geohash.

Installation

The easiest way to install PHP Geohash is with composer. Find it on Packagist.

$ composer require saikiran/geohash

Usage

Encode co-ordinates

use Sk\Geohash\Geohash;

$g = new Geohash();
echo $g->encode(17.38000000, 78.42000000, 5);

The result is

tepfb

Decode geohash into geographical coordinates

use Sk\Geohash\Geohash;

$g = new Geohash();
$coordinates = $g->decode("tepfb", 5);
echo "latitude : " . $coordinates[0] . ",  longitude : " . $coordinates[1];

The result is

latitude : 17.38,  longitude : 78.42

Get geohashes of 8 neighbors of a geohash

use Sk\Geohash\Geohash;

$g = new Geohash();
$hash = $g->encode(25.813646, -80.133761, 7);
$neighbors = $g->getNeighbors($hash);
echo "Hash: $hash\n";
echo "Neighbors: " . json_encode($neighbors) . "\n";

The result is

Hash: 
Neighbors: {"North":"dhx4be2","East":"dhx4be1","South":"dhx4bdb","West":"dhx4b7p","NorthEast":"dhx4be3","SouthEast":"dhx4bdc","SouthWest":"dhx4b6z","NorthWest":"dhx4b7r"}

Running the unit tests

Go to this directory from your project folder

$ cd vendor/saikiran/geohash

Then run these two commands

$ composer install
$ vendor/bin/phpunit tests

See these resources online:

geohash's People

Contributors

brasizza avatar craastad avatar skthon 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

Watchers

 avatar

geohash's Issues

Deprecated curly braces

Please fix the issue below it happens on PHP 7.4

Array and string offset access syntax with curly braces is deprecated in /home11/rezasaze/public_html/wooflyapp.com/vendor/saikiran/geohash/src/Geohash.php on line 231

getNeighbors returns empty neighbors

Hello, Thx for your work !

But there are troubles with neighbors calculation...

Here a log from my app :

Geohash 'spgr' ([44.91,4.75]) : neighbors : {"North":"","East":"spgx","South":"spgq","West":"spgp","NorthEast":"","SouthEast":"spgw","SouthWest":"spgn","NorthWest":""}

Doesn't seem possible. Can you check it and fix ?

Decode issue

Hi !

I have an issue with the decode function, it returns the same result for three differents hashes.

example :

  • spex ; spey ; spew

If someone know how to fix it.

Thanks you all.

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.