Geo::USCensus::Geocoding - The U.S. Census Bureau geocoding service
-=head1 VERSION
-
-Version 0.01
-
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
our $DEBUG = 0;
=head1 SYNOPSIS
# required fields
street => '123 Main Street',
city => 'San Francisco', # city
- state => 'CA', # state/province
- zip => '93102', # zip/postal code
+ state => 'CA', # state
# optional fields
+ zip => '93102', # zip code
benchmark => 'Public_AR_ACS2013', # default is "Public_AR_Current"
vintage => 'Census2010_ACS2013', # default is "Current_Current"
=cut
my $ua = LWP::UserAgent->new;
-my $url = 'http://geocoding.geo.census.gov/geocoder/geographies/addressbatch';
+my $url = 'https://geocoding.geo.census.gov/geocoder/geographies/addressbatch';
my $csv = Text::CSV->new({eol => "\n", binary => 1});
my @row = ( 1 ); # first element = row identifier
# at some point support multiple rows in a single query?
+ if (!$opt{street}) {
+ $result->error_message("Street address is required.");
+ return $result;
+ }
+ if (!$opt{zip} and (!$opt{city} or !$opt{state})) {
+ $result->error_message("Either city/state or zip code is required.");
+ return $result;
+ }
foreach (qw(street city state zip)) {
- if (!length($opt{$_})) {
- $result->error_message("$_ required");
- return $result;
- }
- push @row, $opt{$_};
+ push @row, $opt{$_} || '';
}
$csv->combine(@row);
$result->is_match(1);
$result->match_level($fields[3]);
$result->address($fields[4]);
- my ($lat, $long) = split(',', $fields[5]);
- $result->latitude($lat);
+ my ($long, $lat) = split(',', $fields[5]);
$result->longitude($long);
+ $result->latitude($lat);
$result->state($fields[8]);
$result->county($fields[9]);
$result->tract($fields[10]);
$result->block($fields[11]);
} else {
$result->is_match(0);
+ $result->match_level($fields[2]); # "No_Match", "Tie"
}
} else {
$result->error_message( $resp->status_line );
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2014 Mark Wells.
+Copyright (C) 2016 Freeside Internet Services, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published