Net::Geohash - The great new Net::Geohash!


Net-Geohash documentation Contained in the Net-Geohash distribution.

Index


Code Index:

NAME

Top

Net::Geohash - The great new Net::Geohash!

VERSION

Top

Version 1.1

SYNOPSIS

Top

Quick summary of what the module does.

Perhaps a little code snippet.

    use Net::Geohash;

    my $ghurl = Net::Geohash::get('37.391012 -122.071873');
    ...

EXPORT

Top

FUNCTIONS

Top

get

The get function accepts a string containing the lat/lon to send to geohash.org for hashing. It returns the fully qualified geohash.org url on success. If an error occurs it will give a warning message and return an empty string.

Location names such as 'Paris, France' can also be given.

AUTHOR

Top

Nick Gerakines, <nick at gerakines.net>

BUGS

Top

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

SUPPORT

Top

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

    perldoc Net::Geohash

You can also look for information at:

* geohash.org

http://geohash.org/

* del.icio.us/tag/geohash

http://del.icio.us/tag/geohash

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Net-Geohash

* CPAN Ratings

http://cpanratings.perl.org/d/Net-Geohash

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Geohash

* Search CPAN

http://search.cpan.org/dist/Net-Geohash

COPYRIGHT & LICENSE

Top


Net-Geohash documentation Contained in the Net-Geohash distribution.

package Net::Geohash;

use strict;
use warnings;

use LWP::UserAgent;

our $VERSION = '1.1';

sub get {
    my ($coords) = shift @_;
    if (! $coords) { warn 'Missing lattitude/longitude param'; return ''; }
    if (@_) { warn 'Extra parameters found.'; return; }
    my $ua = LWP::UserAgent->new();
    $ua->agent('perl-Net-Geohash/' . $VERSION );
    $ua->max_redirect(0);
    my $resp = $ua->get('http://geohash.org/?q=' . $coords);
    if ($resp->code() eq '303') {
        if (my $loc = $resp->header('location')) {
            if ($loc eq 'http://geohash.org/') {
                warn 'geohash.org response indicates that the geocode was invalid.';
                return '';
            }
            return $loc;
        } else {
            return '';
        }
    }
    warn 'geohash.org response was not a redirect, possibly invalid geocoords.';
    return '';
}

1; # End of Net::Geohash