-3

Okay I'm working on finding the latitude and longitude of cities using Perl. I found the Geo::Coder::Google module and have it installed properly, but I'm getting an error when attempting to use it. The first time I got the error I went out and got an API key from Google thinking that was what I was missing, but that didn't solve the error either. Can someone help me figure out what I'm missing?

Here is the error I'm receiving:

Google Maps API returned error: 500 Can't verify SSL peers without knowing which Certificate Authorities to trust at test.pl line 7.

Here is the code I'm using right now:

1:#!/usr/bin/perl
2:use strict;
3:use warnings;
4:
5:use Geo::Coder::Google;
6:my $geocoder = Geo::Coder::Google->new( apiver => 3, gl => 'us', apikey => 'My API Key Here' );
7:my $location = $geocoder->geocode( location => 'Mount Vernon, IN' );
8:
9:print "$location->{'geometry'}->{'location'}->{'lat'}";
10:print "$location->{'geometry'}->{'location'}->{'lng'}";
B-K
  • 56
  • 1
  • 4
  • possible duplicate of [perl Client-SSL-Warning: Peer certificate not verified](http://stackoverflow.com/questions/2952493/perl-client-ssl-warning-peer-certificate-not-verified) – geocodezip Feb 27 '16 at 19:22
  • possible duplicate of [How to ignore 'Certificate Verify Failed' error in perl?](http://stackoverflow.com/questions/6795030/how-to-ignore-certificate-verify-failed-error-in-perl) – geocodezip Feb 27 '16 at 19:23
  • 1
    possible duplicate of [How can I get LWP to validate SSL server certificates?](http://stackoverflow.com/questions/74358/how-can-i-get-lwp-to-validate-ssl-server-certificates) – geocodezip Feb 27 '16 at 19:24
  • 1
    Cross-posted on [www.perlmonks.org](http://www.perlmonks.org/?node_id=1156330) – Borodin Feb 27 '16 at 21:15
  • Unfortunately the links you have attempt to say are duplicates do not provide any form of assistance answering my question. I do not understand how they even are applicable to this. – B-K Feb 27 '16 at 23:54
  • While it may be acceptable to cross-post the same question to multiple sites, it is considered to be bad form unless you say clearly that you have done so. It is unfair to keep people working on a solution to your problem when it may have been solved already by subscribers to a different site altogether – Borodin Feb 28 '16 at 01:41

2 Answers2

4

The code you have written works fine as it stands—you don't need an API key. The problem is that your Secure Socket Layer support for the HTTPS is incomplete

You should start by reinstalling the LWP library to make sure that it is up to date. You should also install Mozilla::CA to make sure that the Certificates of Authority are current. (This is the most likely cause of the problem given the error message that you're getting.)

If it is still not working after that, then the only other culprits I can think of are IO::Socket::SSL and Crypt::SSLeay, but I would be surprised if they are out of date as they should be updated as dependencies of LWP

#!/usr/bin/perl

use strict;
use warnings 'all';

use Geo::Coder::Google;

my $geocoder = Geo::Coder::Google->new( apiver => 3 );
my $info = $geocoder->geocode( location => 'Mount Vernon, IN' );

my $location = $info->{geometry}{location};

printf "%s %s\n", $location->{lat}, $location->{lng};

output

37.9322662 -87.8950267
Borodin
  • 126,100
  • 9
  • 70
  • 144
1

Try:

sudo cpan

install LMP::UserAgen Mozilla::CA

landonandrey
  • 1,271
  • 1
  • 16
  • 26