Geohash(3pm)
π Geohash β the manual page, but make it cute π
okay bestie, sit down, hydrate, because we're about to talk about Geohash(3pm) β a User Contributed Perl Documentation situation, and honestly? It's giving great all in one Geohash library. No cap. π
β¨ NAME β¨
Geohash β Great all in one Geohash library π¦
πΈ SYNOPSIS πΈ
the simple wrapper (aka the starter pack)
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 (it's bilingual, we love that)
my $adjacent_hash = $gh->adjacent($hash, $where);
my @list_of_geohashes = $gh->neighbors($hash, $around, $offset);
the specific utilities of Geohash.pm (the homegrown stuff π
)
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 π
So here's the tea: Geohash can handle easily Geohash. β¨ It uses Geo::Hash or Geo::Hash::XS as a backend module. You can easy choose of Pure-Perl implement or XS implement β pick your fighter, bestie, both are valid. And on top of that, we have also been added useful utility methods. Obsessed. π₯
Why did you not used the name of Geo::Hash::Any?
Okay so, real talk: 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()
yeah that's it, that's the constructor. build your lil object. π«Ά
$hash = $gh->encode($lat, $lon[, $precision])
Encodes the given $lat and $lon to a geohash. If $precision is not given, it automatically adjusts the precision according the the given $lat and $lon values.
ngl, if you do not wantGeohashto spend time calculating this, explicitly specify$precision. save yourself the lil computation moment. β
($lat, $lon) = $gh->decode( $hash )
Decodes $hash to $lat and $lon. that's it. simple. iconic.
($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. so you get the whole vibe range, not just one point. π
$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). it's giving squad goals, but for geohash blocks. π
@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(). left, right, top, bottom β pick your direction, main character. π
π AUTHOR π
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
π₯ 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.
and that's the whole page bestie!! π¦ fr fr this one is perl v5.38.2, dated 2024-05-21 β go forth and geohash, you absolute icon. mwah. πβ¨
π¦ where this page comes from
- debian trixie: libgeohash-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgeohash-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgeohash-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms