Google-GeoCoder-Smart

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# NAME

Google::GeoCoder::Smart - Simple Google Geocoding API client

# SYNOPSIS

    use Google::GeoCoder::Smart;

    my $geo = Google::GeoCoder::Smart->new(
      key => $ENV{GOOGLE_MAPS_API_KEY},
    );

    my $response = $geo->geocode_addr({
      address => '1600 Amphitheatre Parkway',
      city    => 'Mountain View',
      state   => 'CA',
      zip     => '94043',
    });

    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`.
- Returns decoded API payloads with `rawJSON` attached for debugging.

# INSTALLATION

    perl Makefile.PL
    make
    make test
    make install

# DEPENDENCIES

Runtime dependencies are declared in `Makefile.PL`:

- `HTTP::Tiny`
- `JSON::PP`
- `URI::Escape`

# TESTING

Run tests with:

    make test

# METHODS

## new

    my $geo = Google::GeoCoder::Smart->new(
      key    => 'your-api-key',
      host   => 'maps.googleapis.com', # optional
      scheme => 'https',               # optional
      timeout => 10,                   # optional
    );

## `geocode_addr`

    my $response = $geo->geocode_addr({
      address   => '1600 Amphitheatre Parkway',
      city      => 'Mountain View',
      state     => 'CA',
      zip       => '94043',
      language  => 'en',
      region    => 'us',
      place_id  => 'ChIJ2eUgeAK6j4ARbn5u_wAGqWA',
      components => {
        country => 'US',
      },
    });

Returns a hashref mirroring Google API JSON.



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