Skip to content

Commit

Permalink
Support lookups of British counties e.g. 'Kent, England'
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 7, 2018
1 parent 2fe88cd commit e02a18a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Revision history for Geo-Coder-Free

0.15
Added alternatives table, for when a place could be listed elsewhere
Support lookups of British counties e.g. 'Kent, England'

0.14 Fri Sep 7 16:07:39 EDT 2018
Work on fixing http://www.cpantesters.org/cpan/report/6b68841a-8cc6-11e8-98d5-bb14e5798fec
Expand Down
13 changes: 11 additions & 2 deletions lib/Geo/Coder/Free/MaxMind.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub geocode {
$county =~ s/\s$//g;
$state =~ s/^\s//g;
$state =~ s/\s$//g;
$country =~ s/^\s//g;
# $country =~ s/^\s//g;
$country =~ s/\s$//g;
} elsif($location =~ /^[\w\s-],[\w\s-]/) {
Carp::carp(__PACKAGE__, ": can't parse and handle $location");
Expand All @@ -174,16 +174,24 @@ sub geocode {
$location =~ s/^\s//g;
$location =~ s/\s$//g;
$country = uc($region);
} elsif($location =~ /^(\w+),\s*(\w+)$/) {
# } elsif(0) {
$county = $1;
$country = $2;
$county =~ s/^\s//g;
$county =~ s/\s$//g;
# $country =~ s/^\s//g;
$country =~ s/\s$//g;
} else {
# Carp::croak(__PACKAGE__, ' only supports towns, not full addresses');
return;
}
if($country) {
my $countrycode = country2code($country);
if(defined($country) && (($country eq 'UK') || ($country eq 'United Kingdom') || ($country eq 'England'))) {
$country = 'Great Britain';
$concatenated_codes = 'GB';
}
my $countrycode = country2code($country);

if($state && $admin1cache{$state}) {
$concatenated_codes = $admin1cache{$state};
Expand Down Expand Up @@ -319,6 +327,7 @@ sub geocode {
}

my $options = { City => lc($location) };
$options->{'City'} =~ s/,\s*\w+$//;
if($region) {
if($region =~ /^.+\.(.+)$/) {
$region = $1;
Expand Down
9 changes: 7 additions & 2 deletions t/maxmind.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use warnings;
use strict;
use Test::Most tests => 72;
use Test::Most tests => 75;
use Test::Number::Delta;
use Test::Carp;
use lib 't/lib';
Expand Down Expand Up @@ -159,6 +159,11 @@ LOOKUP: {
$location = $geocoder->geocode('Thanet, Kent, England');
ok(defined($location));

$location = $geocoder->geocode('Kent, England');
ok(defined($location));
delta_within($location->{latitude}, 51.25, 1e-2);
delta_within($location->{longitude}, 0.75, 1e-2);

$location = $geocoder->geocode('Vessels, Misc Ships At sea or abroad, England');
ok(!defined($location));

Expand All @@ -174,7 +179,7 @@ LOOKUP: {
});
} else {
diag('Author tests not required for installation');
skip('Author tests not required for installation', 71);
skip('Author tests not required for installation', 74);
}
}
}

0 comments on commit e02a18a

Please sign in to comment.