use HTTP::Request;
use HTTP::Request::Common qw( GET POST );
use HTML::TokeParser;
-use URI::Escape;
+use URI::Escape 3.31;
use Data::Dumper;
FS::UID->install_callback( sub {
} #unless ($res->code eq '200')
- die "FFIEC Geocoding error: $error" if $error;
+ die "FFIEC Geocoding error: $error\n" if $error;
$return->{'statecode'} . $return->{'countycode'} . $return->{'tractcode'};
}
UserID => $userid,
Password => $password,
Testing => 0,
- } ) or die "error starting USPS WebTools";
+ } ) or die "error starting USPS WebTools\n";
my($zip5, $zip4) = split('-',$location->{'zip'});
warn $verifier->response
if $DEBUG > 1;
- die "USPS WebTools error: ".$verifier->{error}{description}
+ die "USPS WebTools error: ".$verifier->{error}{description} ."\n"
if $verifier->is_error;
my $zip = $hash->{Zip5};
addr_clean=> 'Y' }
}
-my %teleatlas_error = ( # USA_Geo_002 documentation
+my %ezlocate_error = ( # USA_Geo_002 documentation
10 => 'State not found',
11 => 'City not found',
12 => 'Invalid street address',
17 => 'Intersection not found', #unused?
);
-sub standardize_teleatlas {
+sub standardize_ezlocate {
my $self = shift;
my $location = shift;
my $class;
- if ( $location->{country} eq 'US' ) {
- $class = 'USA_Geo_004Tool';
- }
- elsif ( $location->{country} eq 'CA' ) {
- $class = 'CAN_Geo_001Tool';
- }
- else { # shouldn't be a fatal error, just pass through unverified address
- warn "standardize_teleatlas: address lookup in '".$location->{country}.
- "' not available\n";
- return $location;
- }
+ #if ( $location->{country} eq 'US' ) {
+ # $class = 'USA_Geo_004Tool';
+ #}
+ #elsif ( $location->{country} eq 'CA' ) {
+ # $class = 'CAN_Geo_001Tool';
+ #}
+ #else { # shouldn't be a fatal error, just pass through unverified address
+ # warn "standardize_teleatlas: address lookup in '".$location->{country}.
+ # "' not available\n";
+ # return $location;
+ #}
+ #my $path = $conf->config('teleatlas-path') || '';
+ #local @INC = (@INC, $path);
+ #eval "use $class;";
+ #if ( $@ ) {
+ # die "Loading $class failed:\n$@".
+ # "\nMake sure the TeleAtlas Perl SDK is installed correctly.\n";
+ #}
+
+ $class = 'Geo::EZLocate'; # use our own library
+ eval "use $class";
+ die $@ if $@;
- my $path = $conf->config('teleatlas-path')
- or die "no teleatlas-path configured";
- my $userid = $conf->config('teleatlas-userid')
- or die "no teleatlas-userid configured";
- my $password = $conf->config('teleatlas-password')
- or die "no teleatlas-password configured";
-
- local @INC = (@INC, $path);
- eval "use $class;";
- if ( $@ ) {
- die "Loading $class failed:\n$@".
- "\nMake sure the TeleAtlas Perl SDK is installed correctly.\n";
- }
+ my $userid = $conf->config('ezlocate-userid')
+ or die "no ezlocate-userid configured\n";
+ my $password = $conf->config('ezlocate-password')
+ or die "no ezlocate-password configured\n";
my $tool = $class->new($userid, $password);
my $match = $tool->findAddress(
$location->{state},
$location->{zip}, #12345-6789 format is allowed
);
- warn "teleatlas returned match:\n".Dumper($match) if $DEBUG > 1;
+ warn "ezlocate returned match:\n".Dumper($match) if $DEBUG > 1;
# error handling - B codes indicate success
- die $teleatlas_error{$match->{MAT_STAT}}."\n"
+ die $ezlocate_error{$match->{MAT_STAT}}."\n"
unless $match->{MAT_STAT} =~ /^B\d$/;
{
zip => $match->{STD_ZIP}.'-'.$match->{STD_P4},
latitude => $match->{MAT_LAT},
longitude => $match->{MAT_LON},
- censustract => $match->{FIPS_ST}.$match->{FIPS_CTY}.$match->{CEN_TRCT},
+ censustract => $match->{FIPS_ST}.$match->{FIPS_CTY}.
+ sprintf('%04.2f',$match->{CEN_TRCT}),
addr_clean => 'Y',
};
}