Geohash(3pm)

πŸ“¦ version 0.04, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– 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 want Geohash to 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