Hi, Thanks for writing this great perl module.
I'd like to geocode using the PlaceFinder fully parsed location input.
I've written a function to do this which I hope you can use as a
starting point to add to the module. It would be probably best if the
function passed through all parameters provided.
Regards,
Kingsley
sub geocode_custom {
my ($self, @params) = @_;
my %params = (@params % 2) ? (location => @params) : @params;
my $house = $params{house};
my $street = $params{street};
my $city = $params{city} or return;
my $state = $params{state} or return;
my $country = $params(country) or return;
$house = Encode::encode('utf-8', $house);
$street = Encode::encode('utf-8', $street);
$city = Encode::encode('utf-8', $city);
$state = Encode::encode('utf-8', $state);
$country = Encode::encode('utf-8', $country);
my $uri = URI->new('http://where.yahooapis.com/geocode');
$uri->query_form(
appid => $self->{appid},
house => $house,
street => $street,
city => $city,
state => $state,
country => $country,
flags => 'JRST',
gflags => 'AC',
map { defined $params{$_} ? ($_ => $params{$_}) : () }
qw(locale start count offset)
);
my $res = $self->{response} = $self->ua->get($uri);
return unless $res->is_success;
# Change the content type of the response from 'application/json' so
# HTTP::Message will decode the character encoding.
$res->content_type('text/plain');
my $data = eval { from_json($res->decoded_content) };
return unless $data;
my @results = @{ $data->{ResultSet}{Results} || [] };
return wantarray ? @results : $results[0];
}