summaryrefslogtreecommitdiff
path: root/FS/FS/Misc
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-09-30 19:32:23 -0700
committerMark Wells <mark@freeside.biz>2013-09-30 19:32:23 -0700
commite7b2e4ef48c2fdc509dba13495d2910c90564929 (patch)
treec6fd78b23e7a431ae8182fbf997be2093a19c843 /FS/FS/Misc
parentb61064b3e9a58881a7ad1c4febff3244fc5a4bcc (diff)
start support for TomTom geocoding, #13763
Diffstat (limited to 'FS/FS/Misc')
-rw-r--r--FS/FS/Misc/Geo.pm47
1 files changed, 47 insertions, 0 deletions
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm
index a93d98f..4dd6dc6 100644
--- a/FS/FS/Misc/Geo.pm
+++ b/FS/FS/Misc/Geo.pm
@@ -10,6 +10,7 @@ use HTML::TokeParser;
use URI::Escape 3.31;
use Data::Dumper;
use FS::Conf;
+use Locale::Country;
FS::UID->install_callback( sub {
$conf = new FS::Conf;
@@ -410,6 +411,52 @@ sub standardize_ezlocate {
\%result;
}
+sub standardize_tomtom {
+ # post-2013 TomTom API
+ # much better, but incompatible with ezlocate
+ my $self = shift;
+ my $location = shift;
+ my $class = 'Geo::TomTom::Geocoding';
+ eval "use $class";
+ die $@ if $@;
+
+ my $key = $conf->config('tomtom-userid')
+ or die "no tomtom-userid configured\n";
+
+ my $country = code2country($location->{country});
+ my $result = $class->query(
+ key => $key,
+ T => $location->{address1},
+ L => $location->{city},
+ AA => $location->{state},
+ PC => $location->{zip},
+ CC => country2code($country, LOCALE_CODE_ALPHA_3),
+ );
+ unless ( $result->is_success ) {
+ die "TomTom geocoding error: ".$result->message."\n";
+ }
+ my ($match) = $result->locations;
+ if (!$match) {
+ die "Location not found.\n";
+ }
+ warn "tomtom returned match:\n".Dumper($match) if $DEBUG > 1;
+ my $tract = join('.', $match->{censusTract} =~ /(....)(..)/);
+ return +{
+ address1 => join(' ', $match->{houseNumber}, $match->{street}),
+ address2 => $location->{address2}, # XXX still need a solution to this
+ city => $match->{city},
+ state => $match->{state},
+ country => country2code($match->{country}, LOCALE_CODE_ALPHA_2),
+ zip => ($match->{standardPostalCode} || $match->{postcode}),
+ latitude => $match->{latitude},
+ longitude => $match->{longitude},
+ censustract => $match->{censusStateCode}.
+ $match->{censusFipsCountyCode}.
+ $tract,
+ addr_clean => 'Y',
+ };
+}
+
=back
=cut