Skip to content

Commit

Permalink
Add Open Location Codes support to search box.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed May 29, 2020
1 parent 2de6554 commit b16c94e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ requires 'Error';
requires 'FCGI'; # Required by e.g. Plack::Handler::FCGI
requires 'File::Find';
requires 'File::Path';
requires 'Geo::OLC';
requires 'Geography::NationalGrid',
mirror => 'https://cpan.metacpan.org/';
requires 'Getopt::Long::Descriptive', '0.105';
Expand Down
9 changes: 9 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,15 @@ DISTRIBUTIONS
perl 5.014000
strict 0
warnings 0
Geo-OLC-1
pathname: J/JG/JGREELY/Geo-OLC-1.tar.gz
provides:
Geo::OLC 1
requirements:
ExtUtils::MakeMaker 0
List::Util 1
Test::More 0
perl 5.010001
Geography-NationalGrid-1.6
pathname: P/PK/PKENT/Geography-NationalGrid-1.6.tar.gz
provides:
Expand Down
9 changes: 9 additions & 0 deletions perllib/FixMyStreet/App/Controller/Location.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BEGIN {extends 'Catalyst::Controller'; }

use Encode;
use FixMyStreet::Geocode;
use Geo::OLC;
use Try::Tiny;
use Utils;

Expand Down Expand Up @@ -74,6 +75,14 @@ sub determine_location_from_pc : Private {
map { Utils::truncate_coordinate($_) } ($1, $2);
return $c->forward( 'check_location' );
}

if (Geo::OLC::is_full($pc)) {
my $ref = Geo::OLC::decode($pc);
($c->stash->{latitude}, $c->stash->{longitude}) =
map { Utils::truncate_coordinate($_) } @{$ref->{center}};
return $c->forward( 'check_location' );
}

if ( $c->cobrand->country eq 'GB' && $pc =~ /^([A-Z])([A-Z])([\d\s]{4,})$/i) {
if (my $convert = gridref_to_latlon( $1, $2, $3 )) {
($c->stash->{latitude}, $c->stash->{longitude}) =
Expand Down
12 changes: 12 additions & 0 deletions t/app/controller/around.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ foreach my $test (
};
}

subtest "check lat/lng for plus code" => sub {
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => "9C7RXR26+R5" } } );
is_deeply $mech->page_errors, [], "no errors for plus code";
is_deeply $mech->extract_location, {
pc => "9C7RXR26+R5",
latitude => 55.952063,
longitude => -3.189562,
},
"got expected location for plus code";
};

my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id;
my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id;

Expand Down

0 comments on commit b16c94e

Please sign in to comment.