Skip to content

Commit

Permalink
Started work on reverse_geocode()
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Mar 27, 2019
1 parent 924974b commit 051c9b3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Revision history for Geo-Coder-List
0.24
Support the cache option
Test Geo::Coder::Free::Local
Started work on reverse_geocode()

0.23 Fri Feb 1 20:57:05 EST 2019
Add the calling line to the log
Expand Down
39 changes: 37 additions & 2 deletions lib/Geo/Coder/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,43 @@ sub ua {
}
}

=head2 reverse_geocode
Similar to geocode except it expects a latitude/longitude parameter.
print $geocoder_list->reverse_geocode(latlng => '37.778907,-122.39732');
=cut

sub reverse_geocode {
my $self = shift;
my @params = @_;

foreach my $g(@{$self->{geocoders}}) {
if(wantarray) {
my @rc;
if(my @locs = $g->reverse_geocode(@params)) {
foreach my $loc(@locs) {
# OSM
if(my $name = $loc->{'display_name'}) {
CORE::push @rc, $name;
}
}
}
return @rc;
} elsif(my $rc = $g->reverse_geocode(@params)) {
# OSM
if($rc = $rc->{'display_name'}) {
return $rc;
}
}
}
}

=head2 log
Returns the log of events to help you debug failures, optimize lookup order and fix quota breakage
Returns the log of events to help you debug failures,
optimize lookup order and fix quota breakage.
my @log = @{$geocoderlist->log()};
Expand Down Expand Up @@ -476,7 +510,8 @@ L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geo-Coder-List>.
I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
There is no reverse_geocode() yet.
reverse_geocode() doesn't update the logger.
reverse_geocode() should support L<Geo::Location::Point> objects.
=head1 SEE ALSO
Expand Down
9 changes: 6 additions & 3 deletions t/osm.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::Most tests => 33;
use Test::Most tests => 34;
use Test::NoWarnings;

eval 'use autodie qw(:all)'; # Test for open/close failures
Expand All @@ -13,7 +13,7 @@ BEGIN {

OSM: {
SKIP: {
skip 'Test requires Internet access', 31 unless(-e 't/online.enabled');
skip 'Test requires Internet access', 32 unless(-e 't/online.enabled');

eval {
require Geo::Coder::OSM;
Expand All @@ -31,7 +31,7 @@ OSM: {

if($@) {
diag('Geo::Coder::OSM not installed - skipping tests');
skip 'Geo::Coder::OSM not installed', 31;
skip('Geo::Coder::OSM not installed', 32);
} else {
diag("Using Geo::Coder::OSM $Geo::Coder::OSM::VERSION");
}
Expand Down Expand Up @@ -73,6 +73,9 @@ OSM: {
ok(ref($location) eq 'HASH');
delta_within($location->{geometry}{location}{lat}, 39.00, 1e-1);
delta_within($location->{geometry}{location}{lng}, -77.10, 1e-1);

like($geocoderlist->reverse_geocode('39.00,-77.10'), qr/Bethesda/i, 'test reverse geocode');

ok($location->{address}{country_code} eq 'us');
like($location->{address}{country}, qr/USA$/, 'check USA');

Expand Down

0 comments on commit 051c9b3

Please sign in to comment.