Skip to content

Commit

Permalink
Fall back to unabbreviated
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 8, 2020
1 parent 7f890ef commit 60bf65c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -465,36 +465,45 @@ sub geocode {
$state = $twoletterstate;
}
}
my %args = (state => $state, country => 'US');
if($href->{city}) {
$city = $args{city} = uc($href->{city});
$city = uc($href->{city});
}
if($href->{number}) {
$args{number} = $href->{number};
}
if($street = $href->{street}) {
# Unabbreviated - look up both, helps with fallback to Maxmind
my $fullstreet = $href->{'street'};
if($street = $fullstreet) {
$fullstreet .= ' ' . $href->{'type'};
if(my $type = Geo::Coder::Free::_abbreviate($href->{'type'})) {
$street .= " $type";
}
if($href->{suffix}) {
$street .= ' ' . $href->{suffix};
$fullstreet .= ' ' . $href->{suffix};
}
}
if($street) {
if(my $prefix = $href->{prefix}) {
$street = "$prefix $street";
$fullstreet = "$prefix $fullstreet";
}
$args{street} = uc($street);
if($href->{'number'}) {
# ::diag($href->{'number'}, "$street$city$state", 'US');
if($rc = $self->_get($href->{'number'}, "$street$city$state", 'US')) {
$rc->{'country'} = 'US';
return $rc;
}
if($rc = $self->_get($href->{'number'}, "$fullstreet$city$state", 'US')) {
$rc->{'country'} = 'US';
return $rc;
}
}
if($rc = $self->_get("$street$city$state", 'US')) {
$rc->{'country'} = 'US';
return $rc;
}
if($rc = $self->_get("$fullstreet$city$state", 'US')) {
$rc->{'country'} = 'US';
return $rc;
}
}
warn "Fast lookup of US location '$location' failed";
} else {
Expand Down

0 comments on commit 60bf65c

Please sign in to comment.