The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Geo::Code - The GeoCode of a latitude,longitude point is a ten byte string, three geonames, or a hybrid code. This Perl module converts between them.

VERSION

Version 1.2

SYNOPSIS

        use Geo::Code;
        my $g = Geo::Code->new();
        my $geocode = $g->geocode(lat=>45.900,lon=>-64.363, geoname => 1);
 
        # geoname can take one of three values => {0,1,2}. 0 -> Alphanumeric, 1 -> three geonames, 2 -> hybrid string (one geoname and a string).
                     
        # Example 1 (Alphanumeric Geo::Code)

        #!/usr/bin/perl
        use strict;
        use Geo::Code;
        my $g = Geo::Code->new();
        my $geocode = $g->geocode(lat=>45.900,lon=>-64.363, geoname => 0);

        print "The geocode is $geocode\n";

        #expected response
        The geocode is EHBSYSEIAH

        # Example 2 (Triple Name Geo::Code)

        #!/usr/bin/perl
        use strict;
        use Geo::Code;
        my $g = Geo::Code->new();
        my $geocode = $g->geocode(lat=>45.900,lon=>-64.363, geoname => 1);

        print "The geocode is $geocode\n";

        #expected response
        The geocode is MONCTON-JIJE-COAK


        # Example 3 (Hybrid Geo::Code)

        #!/usr/bin/perl
        use strict;
        use Geo::Code;
        my $g = Geo::Code->new();
        my $geocode = $g->geocode(lat=>45.900,lon=>-64.363, geoname => 2);

        print "The geocode is $geocode\n";

        #expected response
        The geocode is MONCTON-5BCIZRD


        # Example 4 (Convert a Geo::Code back to Latitude,Longitude)

        #!/usr/bin/perl
        use strict;
        use Geo::Code;
        my $g = Geo::Code->new();
        my $geocode='EHBSYSEIAH';
        my $xy = $g->geocode(gc=>$geocode);
        my ($lat,$lon) = @$xy;
        print "The latitude,longitude of $geocode is ($lat,$lon)\n";

        my $geocode='MONCTON-JIJE-COAK';
        my $xy = $g->geocode(gc=>$geocode);
        my ($lat,$lon) = @$xy;
        print "The latitude,longitude of $geocode is ($lat,$lon)\n";

        my $geocode='MONCTON-5BCIZRD';
        my $xy = $g->geocode(gc=>$geocode);
        my ($lat,$lon) = @$xy;
        print "The latitude,longitude of $geocode is ($lat,$lon)\n";


        #expected response
        The latitude,longitude of EHBSYSEIAH is (45.90000,-64.36300)
        The latitude,longitude of MONCTON-JIJE-COAK is (45.90000,-64.36300)
        The latitude,longitude of MONCTON-5BCIZRD is (45.90000,-64.36300)

DESCRIPTION

Encoding geographic coordinates into a string is a trivial thing. Yet, there are many grid based systems (geohash, PlusCodes, Mapcodes), and some even turn the thing into a business (Zippr, What3Words). I agree with the commonly stated motivation that Latitude and Longitude are not sufficient for identifying a place in both an unambiguous and human friendly way. A single string for this pair of numbers is a better representation, if only it can preserve all the information contained in the original latitude,longitude pair, something no existing geo-encoding system does. That's my goal.

Geo::Code is an open source Geolocation Code. It translates between (latitude,longitude) and three types of one dimensional string (one alphanumeric string, a triple geoname combination or a hybrid).

The Alphanumeric Geo::Code is shorter than most alternatives (10 bytes), has higher accuracy (up to 1 meters) and avoids the borderline discontinuities of other one-dimensional location codes such a geohashes and plus codes.

Triple Name Geo::Code is more human readable than alternatives because it uses actual geographic names and maintains location proximity to the latitude,longitude point, with the first geoname in the triple representing the most prominent geo name within 146.3 km of the point. No geoname is longer than 8 bytes.

The hybrid Geo::Code is composed of two parts, one geoname and an alphanumeric string. The Geoname represents the most promiment location name in the points vicinity while the alphanumeric string part indicates weather two points are far or near, based on how many significant digits they have in common.

This module is explained in more detailed on GitHub. View on GitHub.

Online Demo. 3Geonames.org.

Also supported on Geocode.xyz.

METHODS

new

my $g = Geo::Code->new();

geocode

my $code = $g->geocode(lat=>45.900,lon=>-64.363, geoname=>0); #if geoname is omited, the default is Alphanumeric Geo::Code

or

my $point = $g->geocode(gc=>'MONCTON-JIJE-COAK');

geocode

REQUIREMENTS

Math::BigInt # lib => 'GMP'; make it run faster

SEE ALSO

https://3geonames.org, https://geocode.xyz

AUTHOR

Ervin Ruci, <eruci at geocode.xyz>

BUGS

Please report any bugs or feature requests to bug-geocode at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geo::Code. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Geo::Code

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2018 Ervin Ruci.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

SEE ALSO

Geo::OLC Geohash