Geo-Code
view release on metacpan or search on metacpan
lib/Geo/Code.pm view on Meta::CPAN
package Geo::Code;
use 5.006;
use warnings;
use Math::BigInt lib => 'GMP';
#need Math::BigInt with GMP library support for precision integer arithmetic. otherwise perl returns things like 7-6 = 0.999999999999999
#numlat=7, numlon=6, xy=13, yx=0.999999999999999
#binlat=1101, binlon=0
#
use constant DEBUG => 0;
use constant BASEN => 146300;
use constant BASEA => 36;
use constant PADD => 282699884614999;
use constant ALPHANUMERIC => [ 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z ];
use constant GEONAMETRIPLE => [ ZERO,MELOM,GEIER,OOSTBURG,COLOA,OMACHI,NORRI,LUMAI,KOUMA,IMONO,MCOJE,GADIN,ANGIA,IMATA,BASET,JARPLUND,CAIUA,LWOWEK,GUIPA,OWKAK,ABED,DONGGUAN,PASSE,KAPESTAN,MALSFELD,TABAAN,KITHOR,CAMPANET,ULALA,CAILA,TOMKI,THMEI,ZIHAR...
sub new {
my $class = shift;
my $self = {
};
bless ($self, $class);
return $self;
}
sub geodata {
my $self = shift;
$self->{geodata} = $_[0] if defined $_[0];
return $self->{geodata};
}
sub geocode {
my $self = shift;
my %params = @_;
my $lat = $params{lat} if defined $params{lat};
my $lon = $params{lon} if defined $params{lon};
my $code = uc $params{gc} if defined $params{gc}; #Geo::Code is case insensitive
my $geo3name = $params{geoname} if defined $params{geoname};
if (defined $lat && defined $lon) {
if ($geo3name) {
$self->ngcode($lat,$lon,$geo3name);
} else {
$self->gcode($lat,$lon);
}
} else {
$self->gll($code);
}
my $geodata = $self->geodata;
return $self->geodata;
}
sub gcode {
my $self = shift;
my ($lat,$lon) = @_;
my $geodata = &lltodec($lat,$lon);
return $self->geodata($geodata);
}
sub gll {
my $self = shift;
my $code = shift;
my $geodata = &dencd($code);
return $self->geodata($geodata);
}
sub ngcode {
my $self = shift;
my ($lat,$lon,$geo3name) = @_;
my $geodata = &lltodec($lat,$lon,$geo3name);
return $self->geodata($geodata);
}
sub nencd {
my $decll = shift;
my $base = Math::BigInt->new(BASEN);
( run in 0.627 second using v1.01-cache-2.11-cpan-39bf76dae61 )