Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I'm attempting (poorly) to use the Geo::Coder::Google module to look up locations. I've built a small test block, but even that fails with -
Google Maps API returned error: 403 Forbidden at ./geocode.pl line 6
Nothing appears wrong with the code... does anyone have any ideas?
#!/usr/bin/perl use Geo::Coder::Google; use Data::Dumper; my $geocoder = Geo::Coder::Google->new(apikey => 'google map key her +e -removed'); my $location = $geocoder->geocode( location => 'Hollywood and Highla +nd, Los Angeles, CA' ); print $location;

Replies are listed 'Best First'.
Re: geocoding problem
by tachyon-II (Chaplain) on Dec 17, 2007 at 07:09 UTC

    Assuming you have a valid apikey, the problem may be that Google does not like the LWP::UserAgent user agent string. Does it work if you add this after your call to new (untested):

    $geocoder->ua->agent('Mozilla/5.0');
Re: geocoding problem
by eserte (Deacon) on Dec 17, 2007 at 07:20 UTC
    Seems to work fine here. I have version 0.03 installed.
Re: geocoding problem
by Anonymous Monk on Dec 17, 2007 at 23:58 UTC
    Original poster here
    I finally got it working after much head scratching. Seems the issues was that it needed to know the proxy (it didn't seem to detect the environment varables). So in the interest of sharing code back to the community
    #!/usr/bin/perl use Geo::Coder::Google; use Data::Dumper; use LWP::UserAgent; my $ua = LWP::UserAgent->new(agent => "Geo::Coder::Google/0.01"); $ua->proxy('http', 'http://myproxy.com.au:80'); my $geocoder = Geo::Coder::Google->new(apikey => '{my api key}', ua => + $ua); $geocoder->ua->agent('Mozilla/5.0'); my $location = $geocoder->geocode( location => 'Hollywood and Highla +nd, Los Angeles, CA' ); print Dumper $location;

    Thanks to those whoi responded that it worked. I at least then knew that the problem was at my end, an not with the module.
      If you have the proxy definitions in the usual environment variables, then you can just use $ua->env_proxy

      Also, I think the ->agent definitions are not necessary.