The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Geo::Coder::PlaceFinder - Geocode addresses with Yahoo PlaceFinder

SYNOPSIS

use Geo::Coder::PlaceFinder;

my $geocoder = Geo::Coder::PlaceFinder->new(appid => 'Your App ID');
my $location = $geocoder->geocode(
    location => '701 First Ave, Sunnyvale, CA'
);

DESCRIPTION

The Geo::Coder::PlaceFinder module provides an interface to the Yahoo PlaceFinder geocoding service.

METHODS

new

$geocoder = Geo::Coder::PlaceFinder->new('Your App ID')
$geocoder = Geo::Coder::PlaceFinder->new(
    appid => 'Your App ID',
    # debug => 1,
)

Creates a new geocoding object.

Accepts the following named arguments:

  • appid

    A Yahoo Application ID. (required)

    An ID can be obtained here: https://developer.apps.yahoo.com/dashboard/createKey.html

  • ua

    A custom LWP::UserAgent object. (optional)

  • compress

    Enable compression. (default: 1, unless debug is enabled)

  • debug

    Enable debugging. This prints the headers and content for requests and responses. (default: 0)

geocode

$location = $geocoder->geocode(location => $location)
@locations = $geocoder->geocode(location => $location)

In scalar context, this method returns the first location result; and in list context it returns all location results.

Accepts the following named arguments:

  • location

    The free-form, single line address to be located. (optional)

  • raw

    Returns the raw data structure converted from the response, not split into location results.

Any additional arguments will added to the request. See the Yahoo PlaceFinder documention for the full list of accepted arguments.

By default the following arguments are added:

  • flags

    JRSTX

  • gflags

    AC

Example of the data structure representing a location result:

{
    areacode    => 408,
    boundingbox => {
        east  => "-122.025092",
        north => "37.416275",
        south => "37.416275",
        west  => "-122.025092",
    },
    city        => "Sunnyvale",
    country     => "United States",
    countrycode => "US",
    county      => "Santa Clara County",
    countycode  => "",
    cross =>
        "Near the intersection of 1st Ave and N Mathilda Ave/Bordeaux Dr",
    hash         => "DDAD1896CC0CDC41",
    house        => 701,
    latitude     => "37.416275",
    line1        => "701 1st Ave",
    line2        => "Sunnyvale, CA  94089-1019",
    line3        => "",
    line4        => "United States",
    longitude    => "-122.025092",
    name         => "",
    neighborhood => "",
    offsetlat    => "37.416397",
    offsetlon    => "-122.025055",
    postal       => "94089-1019",
    quality      => 87,
    radius       => 500,
    state        => "California",
    statecode    => "CA",
    street       => {
        stbody   => "1ST",
        stfull   => "1st Ave",
        stpredir => undef,
        stprefix => undef,
        stsufdir => undef,
        stsuffix => "AVE",
    },
    timezone => "America/Los_Angeles",
    unit     => "",
    unittype => "",
    uzip     => 94089,
    woeid    => 12797150,
    woetype  => 11,
    xstreet  => "",
}

Example of the data structure returned using the raw option:

ResultSet => {
    Error        => 0,
    ErrorMessage => "No error",
    Found        => 1,
    Locale       => "us_US",
    Quality      => 60,
    Results      => [ $location ]
    version      => "1.0",
}

response

$response = $geocoder->response()

Returns an HTTP::Response object for the last submitted request. Can be used to determine the details of an error.

ua

$ua = $geocoder->ua()
$ua = $geocoder->ua($ua)

Accessor for the UserAgent object.

SEE ALSO

http://developer.yahoo.com/geo/placefinder/

REQUESTS AND BUGS

Please report any bugs or feature requests to http://rt.cpan.org/Public/Bug/Report.html?Queue=Geo-Coder-PlaceFinder. 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::Coder::PlaceFinder

You can also look for information at:

COPYRIGHT AND LICENSE

Copyright (C) 2010-2011 gray <gray at cpan.org>, all rights reserved.

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

AUTHOR

gray, <gray at cpan.org>