Skip to content

Commit

Permalink
Added new test case which demonstrates a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Feb 24, 2018
1 parent f6c2e5a commit 8bf9f36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Geo/Coder/Free.pm
Expand Up @@ -170,7 +170,8 @@ sub geocode {
$country =~ s/^\s//g;
$country =~ s/\s$//g;
} elsif($self->{openaddr}) {
if($location =~ /^([\w\s\-]+)?,([\w\s]+),([\w\s]+),([\w\s]+),\s*(US|USA|United States|Canada)?$/) {
# if($location =~ /^([\w\s\-]+)?,([\w\s]+),([\w\s]+),([\w\s]+),\s*(US|USA|United States|Canada)?$/) {
if($location =~ /^([\w\s\-]+)?,([\w\s]+),([\w\s]+),([\w\s]+),\s*([\w\s]+)?$/) {
$street = $1;
$location = $2;
$county = $3;
Expand All @@ -184,7 +185,8 @@ sub geocode {
$state =~ s/\s$//g;
$country =~ s/^\s//g;
$country =~ s/\s$//g;
} elsif($location =~ /^([\w\s]+),([\w\s]+),([\w\s]+),\s*(US|USA|United States|Canada)?$/) {
# } elsif($location =~ /^([\w\s]+),([\w\s]+),([\w\s]+),\s*(US|USA|United States|Canada)?$/) {
} elsif($location =~ /^([\w\s]+),([\w\s]+),([\w\s]+),\s*([\w\s]+)?$/) {
$location = $1;
$county = $2;
$state = $3;
Expand All @@ -197,6 +199,13 @@ sub geocode {
$state =~ s/\s$//g;
$country =~ s/^\s//g;
$country =~ s/\s$//g;
} elsif($location =~ /^([\w\s]+),\s*([\w\s]+)?$/) {
$location = $1;
$country = $2;
$location =~ s/^\s//g;
$location =~ s/\s$//g;
$country =~ s/^\s//g;
$country =~ s/\s$//g;
} else {
# TODO: Parse full postal address
die 'TODO - add support for full addresses on openaddr';
Expand Down
3 changes: 3 additions & 0 deletions t/openaddr.t
Expand Up @@ -31,6 +31,9 @@ OPENADDR: {
delta_within($location->{latitude}, 53.55, 1e-2);
delta_within($location->{longitude}, -113.53, 1e-2);

$location = $geocoder->geocode('London, England');
ok(defined($location));

$location = $geocoder->geocode('Silver Spring, Maryland, USA');
ok(defined($location));
delta_within($location->{latitude}, 38.99, 1e-2);
Expand Down

0 comments on commit 8bf9f36

Please sign in to comment.