diff options
author | Mark Wells <mark@freeside.biz> | 2015-03-04 13:29:07 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-03-04 13:29:07 -0800 |
commit | 33f5c81279e1de9afd97adb1872c1b11caf7f6f9 (patch) | |
tree | 56d6e5de016e0c5dda7ed9d1f482e426c8e53e29 /FS/FS/Misc | |
parent | fec65a77360f792a868e51c68c41885b59e62608 (diff) |
add support for U.S. Census geocoding, #32250
Diffstat (limited to 'FS/FS/Misc')
-rw-r--r-- | FS/FS/Misc/Geo.pm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index dbc383a..1e17b5f 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -236,6 +236,8 @@ sub wa_sales { die "WA tax district lookup error: $error"; } +###### USPS Standardization ###### + sub standardize_usps { my $class = shift; @@ -292,6 +294,55 @@ sub standardize_usps { addr_clean=> 'Y' } } +###### U.S. Census Bureau ###### + +sub standardize_uscensus { + my $self = shift; + my $location = shift; + + eval "use Geo::USCensus::Geocoding"; + die $@ if $@; + + if ( $location->{country} ne 'US' ) { + # soft failure + warn "standardize_uscensus not for use in country ".$location->{country}."\n"; + $location->{addr_clean} = ''; + return $location; + } + + my $request = { + street => $location->{address1}, + city => $location->{city}, + state => $location->{state}, + zip => $location->{zip}, + debug => ($DEBUG || 0), + }; + + my $result = Geo::USCensus::Geocoding->query($request); + if ( $result->is_match ) { + # unfortunately we get the address back as a single line + if ($result->address =~ /^(.*), (.*), ([A-Z]{2}), (\d{5}.*)$/) { + return +{ + address1 => $1, + city => $2, + state => $3, + zip => $4, + address2 => uc($location->{address2}), + latitude => $result->latitude, + longitude => $result->longitude, + censustract => $result->censustract, + }; + } else { + die "can't parse address '".$result->address."'"; + } + } else { + warn Dumper($result) if $DEBUG; + die $result->error_message; + } +} + +####### EZLOCATE (obsolete) ####### + sub _tomtom_query { # helper method for the below my %args = @_; my $result = Geo::TomTom::Geocoding->query(%args); |