Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created August 29, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipadsmith/3518789 to your computer and use it in GitHub Desktop.
Save phillipadsmith/3518789 to your computer and use it in GitHub Desktop.
Example of using Google Maps geocoder and the Represent API to return a provincial riding name based on a partial address string
#!/usr/bin/perl
use strict;
use warnings;
use v5.14.2;
use Google::GeoCoder::Smart;
use LWP::Simple;
use JSON;
use Data::Dump qw(dump);
my $geo = Google::GeoCoder::Smart->new();
my $API = 'http://represent.opennorth.ca/boundaries/?sets=british-columbia-electoral-districts&contains=';
# http://represent.opennorth.ca/boundaries/?contains=49.323802%2C-122.947072&format=apibrowser
my ( $resultnum, $error, @results, $returncontent )
= $geo->geocode( "address" => "deep cove, north vancouver, bc" );
$resultnum--;
for my $num ( 0 .. $resultnum ) {
my $lat = $results[$num]{geometry}{location}{lat};
my $long = $results[$num]{geometry}{location}{lng};
my $response = get( $API . $lat . ',' . $long);
die "Couldn't get it!" unless defined $response;
my $boundary_info = decode_json $response;
#say dump( $boundary_info );
say $boundary_info->{'objects'}[0]->{'name'};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment