Skip Menu |

This queue is for tickets about the Geo-Coder-PlaceFinder CPAN distribution.

Report information
The Basics
Id: 63088
Status: resolved
Priority: 0/
Queue: Geo-Coder-PlaceFinder

People
Owner: Nobody in particular
Requestors: kingsleygifford [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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]; }
Subject: fully-parsed address format
On Wed Nov 17 10:30:03 2010, kgifford wrote: Show quoted text
> 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]; > }
0.03 will allow users to pass through any parameters they want. but this will be an undocumented feature. See xt/live.t for a working example. p.s. in the future, keep in mind that a test case can often times be more helpful than actual code.