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

NAME

Geo::Coder::Free::OpenAddresses - Provides a geocoding functionality to a local SQLite database containing geo-coding data.

VERSION

Version 0.35

SYNOPSIS

    use Geo::Coder::Free::OpenAddresses;

    # Use a local download of http://results.openaddresses.io/
    my $geocoder;
    if(my $openaddr = $ENV{'OPENADDR_HOME'}) {
        $geocoder = Geo::Coder::Free::OpenAddresses->new(openaddr => $openaddr);
    } else {
        $geocoder = Geo::Coder::Free::OpenAddresses->new(openaddr => '/usr/share/geo-coder-free/data');
    }
    my $location = $geocoder->geocode(location => '1600 Pennsylvania Avenue NW, Washington DC, USA');

    my @matches = $geocoder->geocode({ scantext => 'arbitrary text', region => 'GB' });

DESCRIPTION

Geo::Coder::Free::OpenAddresses provides an interface to the free geolocation databases at http://results.openaddresses.io, https://github.com/whosonfirst-data, https://github.com/dr5hn/countries-states-cities-database.git and https://download.geofabrik.de/europe-latest.osm.bz2. The SQLite database is in a file held in $OPENADDR_HOME/openaddresses.sql.

Refer to the source URL for licencing information for these files.

To install, run the createdatabases.PL script which imports the data into an SQLite database. This process will take some time.

METHODS

new

    $geocoder = Geo::Coder::Free::OpenAddresses->new(openaddr => $ENV{'OPENADDR_HOME'});

Takes an optional parameter directory, which is the directory of the file openaddresses.sql.

Takes an optional parameter cache, which points to an object that understands get() and set() messages to store data in

geocode

    $location = $geocoder->geocode(location => $location);

    print 'Latitude: ', $location->lat(), "\n";
    print 'Longitude: ', $location->long(), "\n";

    # TODO:
    # @locations = $geocoder->geocode('Portland, USA');
    # diag 'There are Portlands in ', join (', ', map { $_->{'state'} } @locations);

When looking for a house number in a street, if that address isn't found but that street is found, a place in the street is given. So "106 Wells Street, Fort Wayne, Allen, Indiana, USA" isn't found, a match for "Wells Street, Fort Wayne, Allen, Indiana, USA" will be given instead. Arguably that's incorrect, but it is the behaviour I want.

reverse_geocode

    $location = $geocoder->reverse_geocode(latlng => '37.778907,-122.39732');

To be done.

ua

Does nothing, here for compatibility with other geocoders

AUTHOR

Nigel Horne <njh@bandsman.co.uk>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The contents of lib/Geo/Coder/Free/OpenAddresses/databases comes from the places listed in the synopsis.

BUGS

Lots of lookups fail at the moment.

There are die()s where the code path has yet to be written.

The openaddresses data doesn't cover the globe.

Can't parse and handle "London, England".

Currently only searches US and Canadian data.

If you do search in the UK, only look up towns, full addresses aren't included. So these will print the same.

    use Geo::Coder::Free::OpenAddresses;

    $location = $geo_coder->geocode(location => '22 Central Road, Ramsgate, Kent, England');
    print $location->{latitude}, "\n";
    print $location->{longitude}, "\n";
    $location = $geo_coder->geocode(location => '7 Hillbrow Road, St Lawrence, Thanet, Kent, England');
    print $location->{latitude}, "\n";
    print $location->{longitude}, "\n";

When I added the WhosOnFirst data I should have renamed this as it contains data from both sources.

The database shouldn't be called $OPENADDR_HOME/openaddresses.sql, since the datbase now also includes data from WhosOnFirst.

SEE ALSO

VWF, openaddresses.

LICENSE AND COPYRIGHT

Copyright 2017-2023 Nigel Horne.

The program code is released under the following licence: GPL for personal use on a single computer. All other users (including Commercial, Charity, Educational, Government) must apply in writing for a licence for use from Nigel Horne at `<njh at nigelhorne.com>`.