Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
t
xt
.gitignore
.shipit
Changes
MANIFEST.SKIP
Makefile.PL
README
README.mkdn

README.mkdn

NAME

Geohash - Great all in one Geohash library

SYNOPSIS

simple wrapper

use Geohash;
my $gh = Geohash->new();
my $hash = $gh->encode( $lat, $lon );  # default precision = 32
my $hash = $gh->encode( $lat, $lon, $precision );
my ($lat, $lon) = $gh->decode( $hash );
my ($lat_range, $lon_range) = $gh->decode_to_interval( $hash );
my $precision = $gh->precision($lat, $lon);

compatible with Pure Perl and XS

my $adjacent_hash = $gh->adjacent($hash, $where);
my @list_of_geohashes = $gh->neighbors($hash, $around, $offset);

specific utilities of Geohash.pm

my @list_of_merged_geohashes = $gh->merge(@list_of_geohashes);
my @list_of_geohashes = $gh->split(@list_of_merged_geohashes);
my $bool = $gh->validate( $geohash );

fource use pp

BEGIN { $ENV{PERL_GEOHASH_BACKEND} = 'Geo::Hash' } use Geohash;

fource use xs

BEGIN { $ENV{PERL_GEOHASH_BACKEND} = 'Geo::Hash::XS' } use Geohash;

DESCRIPTION

Geohash can handle easily Geohash. Geohash uses Geo::Hash or Geo::Hash::XS as a backend module. You can easy choose of Pure-Perl implement or XS implement. In addition, we have also been added useful utility methods.

Why did you not used the name of Geo::Hash::Any?

Geohash official name is not Geo::Hash. It should not be separated by ::. And I think of *::Any namespace is not preferable.

I think so no problem with increasing the namespace if a namespace that can be used to implement and intuitive.

METHODS

$gh = Geohash->new()

$hash = $gh->encode($lat, $lon[, $precision])

Encodes the given $lat and $lon to a geohash. If $precision is not given, automatically adjusts the precision according the the given $lat and $lon values.

If you do not want Geohash to spend time calculating this, explicitly specify $precision.

($lat, $lon) = $gh->decode( $hash )

Decodes $hash to $lat and $lon

($lat_range, $lon_range) = $gh->decode_to_interval( $hash )

Like decode() but decode_to_interval() decodes $hash to $lat_range and $lon_range. Each range is a reference to two element arrays which contains the upper and lower bounds.

$precision = $gh->precision($lat, $lon)

Returns the apparent required precision to describe the given latitude and longitude.

$adjacent_hash = $gh->adjacent($hash, $where)

Returns the adjacent geohash. $where denotes the direction, so if you want the block to the right of $hash, you say:

use Geohash qw(ADJ_RIGHT);

my $gh = Geohash->new();
my $adjacent = $gh->adjacent( $hash, ADJ_RIGHT );

@list_of_geohashes = $gh->neighbors($hash, $around, $offset)

Returns the list of neighbors (the blocks surrounding $hash)

@list_of_merged_geohashes = $gh->merge(@list_of_geohashes)

Merged with the larger area from geohash list. And remove duplicated geohash in @list_of_geohashes.

my @list = $gh->merge(qw/
    c2b25ps0 c2b25ps1 c2b25ps2 c2b25ps3 c2b25ps4 c2b25ps5 c2b25ps6 c2b25ps7 c2b25ps8 c2b25ps9
    c2b25psb c2b25psc c2b25psd c2b25pse c2b25psf c2b25psg c2b25psh c2b25psj c2b25psk c2b25psm
    c2b25psn c2b25psp c2b25psq c2b25psr c2b25pss c2b25pst c2b25psu c2b25psv c2b25psw c2b25psx
    c2b25psy c2b25psz
/);
is($list[0], 'c2b25ps');

@list_of_geohashes = $gh->split(@list_of_merged_geohashes)

geohash splitter.

my @list = $gh->split('c2b25ps');
is_deeply(\@list, [ qw/
    c2b25ps0 c2b25ps1 c2b25ps2 c2b25ps3 c2b25ps4 c2b25ps5 c2b25ps6 c2b25ps7 c2b25ps8 c2b25ps9
    c2b25psb c2b25psc c2b25psd c2b25pse c2b25psf c2b25psg c2b25psh c2b25psj c2b25psk c2b25psm
    c2b25psn c2b25psp c2b25psq c2b25psr c2b25pss c2b25pst c2b25psu c2b25psv c2b25psw c2b25psx
    c2b25psy c2b25psz
/ ]);

$bool = $gh->validate($geohash)

Verify correct as geohash.

ok($gh->validate('c2b25ps0');
ok(not $gh->validate('a'); # can not use 'a'
ok(not $gh->validate(); # required option

CONSTANTS

ADJ_LEFT, ADJ_RIGHT, ADJ_TOP, ADJ_BOTTOM

Used to specify the direction in adjacent()

AUTHOR

Kazuhiro Osawa

SEE ALSO

Geo::Hash, Geo::Hash::XS, http://en.wikipedia.org/wiki/Geohash, http://geohash.org/

THANKS TO

dirkus, tokuhirom, nipotan

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Something went wrong with that request. Please try again.