NAME

Geo::GeoNames - Perform geographical queries using GeoNames Web Services

VERSION

Version 1.15

SYNOPSIS

    use Geo::GeoNames;
    my $geo = Geo::GeoNames->new(username => $ENV{'GEONAME_USER'});

    # make a query based on placename
    my $result = $geo->search(q => 'Fredrikstad', maxRows => 2);

    # print the first result
    print ' Name: ', $result->[0]->{name}, "\n";
    print ' Longitude: ', $result->[0]->{lng}, "\n";
    print ' Latitude: ', $result->[0]->{lat}, "\n";

    # Make a query based on postcode
    $result = $geo->postalcode_search(
            postalcode => '1630', maxRows => 3, style => 'FULL'
    );

DESCRIPTION

Before you start, get a free GeoNames account and enable it for access to the free web service:

Provides a perl interface to the webservices found at http://api.geonames.org. That is, given a given placename or postalcode, the module will look it up and return more information (longitude, latitude, etc) for the given placename or postalcode. Wikipedia lookups are also supported. If more than one match is found, a list of locations will be returned.

ua

Accessor method to get and set UserAgent object used internally. You can call env_proxy for example, to get the proxy information from environment variables:

$geo_coder->ua()->env_proxy(1);

You can also set your own User-Agent object:

use LWP::UserAgent::Throttled;
$geo_coder->ua(LWP::UserAgent::Throttled->new());

SUBROUTINES/METHODS

RETURNED DATASTRUCTURE

The datastructure returned from methods in this module is an array of hashes. Each array element contains a hash which in turn contains the information about the placename/postalcode.

For example, running the statement

    my $result = $geo->search(
            q => "Fredrikstad", maxRows => 3, style => "FULL"
            );

yields the result:

    $VAR1 = {
            'population' => {},
            'lat' => '59.2166667',
            'elevation' => {},
            'countryCode' => 'NO',
            'adminName1' => "\x{d8}stfold",
            'fclName' => 'city, village,...',
            'adminCode2' => {},
            'lng' => '10.95',
            'geonameId' => '3156529',
            'timezone' => {
                    'dstOffset' => '2.0',
                    'content' => 'Europe/Oslo',
                    'gmtOffset' => '1.0'
                    },
            'fcode' => 'PPL',
            'countryName' => 'Norway',
            'name' => 'Fredrikstad',
            'fcodeName' => 'populated place',
            'alternateNames' => 'Frederikstad,Fredrikstad,Fredrikstad kommun',
            'adminCode1' => '13',
            'adminName2' => {},
            'fcl' => 'P'
            };

The elements in the hashes depends on which style is passed to the method, but will always contain name, lng, and lat except for postalcode_country_info(), find_nearest_address(), find_nearest_intersection(), and find_nearby_streets().

BUGS

This module is provided as-is without any warranty.

Not a bug, but the GeoNames services expects placenames to be UTF-8 encoded, and all data received from the webservices are also UTF-8 encoded. So make sure that strings are encoded/decoded based on the correct encoding.

Please report any bugs found or feature requests through GitHub issues https://github.com/nigelhorne/Geo-GeoNames/issues. or bug-geo-geonamnes at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geo-GeoNames. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

SOURCE AVAILABILITY

The source code for this module is available from Github at https://github.com/nigelhorne/Geo-GeoNames.

AUTHOR

Per Henrik Johansen, <per.henrik.johansen@gmail.com>.

Previously maintained by brian d foy, <brian.d.foy@gmail.com> and Nicolas Mendoza, <mendoza@pvv.ntnu.no>

Maintained by Nigel Horne, <njh at nigelhorne.com>

COPYRIGHT AND LICENSE

Copyright (C) 2007-2021 by Per Henrik Johansen Copyright (C) 2022-2023 by Nigel Horne

This library is available under the Artistic License 2.0.