Google-GeoCoder-Smart

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


    die "Error: $response->{status}" if $response->{status} ne 'OK';

    my $best_match = $response->{results}[0];
    my $lat = $best_match->{geometry}{location}{lat};
    my $lng = $best_match->{geometry}{location}{lng};

# DESCRIPTION

[Google::GeoCoder::Smart](https://metacpan.org/pod/Google::GeoCoder::Smart) provides a lightweight wrapper around the Google Geocoding API
v3 endpoint:

    https://maps.googleapis.com/maps/api/geocode/json

It supports both structured addresses and place IDs, and returns decoded API
payloads with `rawJSON` attached for debugging.

# WHAT THIS MODULE DOES

- Sends geocoding requests to `https://maps.googleapis.com/maps/api/geocode/json`.
- Supports structured address parts, `place_id`, and optional `language`, `region`, `bounds`, and `components`.

lib/Google/GeoCoder/Smart.pm  view on Meta::CPAN


  die "Error: $response->{status}" if $response->{status} ne 'OK';

  my $best_match = $response->{results}[0];
  my $lat = $best_match->{geometry}{location}{lat};
  my $lng = $best_match->{geometry}{location}{lng};

=head1 DESCRIPTION

L<Google::GeoCoder::Smart|https://metacpan.org/pod/Google::GeoCoder::Smart> provides a lightweight wrapper around the Google Geocoding API
v3 endpoint:

  https://maps.googleapis.com/maps/api/geocode/json

It supports both structured addresses and place IDs, and returns decoded API
payloads with C<rawJSON> attached for debugging.

=head1 WHAT THIS MODULE DOES

=over 4

t/Google-GeoCoder-Smart.t  view on Meta::CPAN

      address => '1600 Amphitheatre Parkway',
      city    => 'Mountain View',
      state   => 'CA',
      zip     => '94043',
      language => 'en',
    });

    is($response->{status}, 'OK', 'status is OK');
    is(scalar @{ $response->{results} }, 1, 'one result returned');
    is($response->{results}[0]{geometry}{location}{lat}, 37.422, 'latitude parsed');
    like($captured_url, qr{/maps/api/geocode/json\?}, 'uses geocode endpoint');
    like($captured_url, qr/key=test-key/, 'includes key');
    unlike($captured_url, qr/sensor=/, 'does not use deprecated sensor parameter');
  }
};

subtest 'legacy geocode wrapper still works' => sub {
  my $geo = Google::GeoCoder::Smart->new();

  {
    no warnings 'redefine';



( run in 0.732 second using v1.01-cache-2.11-cpan-39bf76dae61 )