GeoHash - Geo::Hash* wrapper with any utils
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;
GeoHash is a wrapper module for use in the same interface and Geo::Hash Geo::Hash::XS. and utility method has been added to it.
You can use the methods in the Geo::Hash has been implemented in only Geo::Hash::XS.
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.
$lat
$lon
$precision
If you do not want GeoHash to spend time calculating this, explicitly specify $precision.
Decodes $hash to $lat and $lon
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.
decode()
decode_to_interval()
Returns the apparent required precision to describe the given latitude and longitude.
Returns the adjacent geohash. $where denotes the direction, so if you want the block to the right of $hash, you say:
$where
$hash
use GeoHash qw(ADJ_RIGHT); my $gh = GeoHash->new(); my $adjacent = $gh->adjacent( $hash, ADJ_RIGHT );
Returns the list of neighbors (the blocks surrounding $hash)
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');
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 / ]);
Verify correct as geohash.
ok($gh->validate('c2b25ps0'); ok(not $gh->validate('a'); # can not use 'a' ok(not $gh->validate(); # required option
Used to specify the direction in adjacent()
adjacent()
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
Geo::Hash, Geo::Hash::XS
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install GeoHash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GeoHash
CPAN shell
perl -MCPAN -e shell install GeoHash
For more information on module installation, please visit the detailed CPAN module installation guide.