diff options
Diffstat (limited to 'perllib/FixMyStreet/Cobrand')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 35 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixaMinGata.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 34 |
4 files changed, 34 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 99b247412..92494250e 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -5,6 +5,7 @@ use strict; use warnings; use FixMyStreet; use FixMyStreet::DB; +use FixMyStreet::Geocode::Address; use FixMyStreet::Geocode::Bing; use DateTime; use List::MoreUtils 'none'; @@ -514,34 +515,32 @@ sub geocoded_string_check { return 1; } =item find_closest Used by send-reports and similar to attach nearest things to the bottom of the -report. +report. This can be called with either a hash of lat/lon or a Problem. =cut sub find_closest { - my ( $self, $problem, $as_data ) = @_; + my ($self, $data) = @_; + $data = { problem => $data } if ref $data ne 'HASH'; + + my $problem = $data->{problem}; + my $lat = $problem ? $problem->latitude : $data->{latitude}; + my $lon = $problem ? $problem->longitude : $data->{longitude}; + my $j = $problem->geocode if $problem; - my $j = $problem->geocode; if (!$j) { - $j = FixMyStreet::Geocode::Bing::reverse( $problem->latitude, $problem->longitude, + $j = FixMyStreet::Geocode::Bing::reverse( $lat, $lon, disambiguate_location()->{bing_culture} ); - # cache the bing results for use in alerts - $problem->geocode( $j ); - $problem->update; - } - - my $data = $as_data ? {} : ''; - if ($j && $j->{resourceSets}[0]{resources}[0]{name}) { - my $str = $j->{resourceSets}[0]{resources}[0]{name}; - if ($as_data) { - $data->{road} = $str; - } else { - $data .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), - $str) . "\n\n"; + if ($problem) { + # cache the bing results for use in alerts + $problem->geocode( $j ); + $problem->update; } } - return $data; + return FixMyStreet::Geocode::Address->new($j->{resourceSets}[0]{resources}[0]) + if $j && $j->{resourceSets}[0]{resources}[0]{name}; + return {}; } =item find_closest_address_for_rss diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index e49d5bd47..306ad358a 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -62,6 +62,7 @@ sub geocoded_string_check { sub find_closest { my ( $self, $problem ) = @_; + $problem = $problem->{problem} if ref $problem eq 'HASH'; return FixMyStreet::Geocode::OSM::closest_road_text( $self, $problem->latitude, $problem->longitude ); } diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm index 37dec5a11..29e840dfa 100644 --- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -122,6 +122,7 @@ sub geocoded_string_check { sub find_closest { my ( $self, $problem ) = @_; + $problem = $problem->{problem} if ref $problem eq 'HASH'; return FixMyStreet::Geocode::OSM::closest_road_text( $self, $problem->latitude, $problem->longitude ); } diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 0ecb6a7c6..f99f29eb4 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -117,27 +117,23 @@ sub short_name { } sub find_closest { - my ( $self, $problem, $as_data ) = @_; - - my $data = $self->SUPER::find_closest($problem, $as_data); - - my $mapit_url = FixMyStreet->config('MAPIT_URL'); - my ($lat, $lon) = map { Utils::truncate_coordinate($_) } $problem->latitude, $problem->longitude; - my $url = $mapit_url . "nearest/4326/$lon,$lat"; - my $j = LWP::Simple::get($url); - if ($j) { - $j = JSON->new->utf8->allow_nonref->decode($j); - if ($j->{postcode}) { - if ($as_data) { - $data->{postcode} = $j->{postcode}; - } else { - $data .= sprintf(_("Nearest postcode to the pin placed on the map (automatically generated): %s (%sm away)"), - $j->{postcode}{postcode}, $j->{postcode}{distance}) . "\n\n"; - } - } + my ($self, $data) = @_; + + $data = { problem => $data } if ref $data ne 'HASH'; + + my $problem = $data->{problem}; + my $lat = $problem ? $problem->latitude : $data->{latitude}; + my $lon = $problem ? $problem->longitude : $data->{longitude}; + + my $closest = $self->SUPER::find_closest($data); + + ($lat, $lon) = map { Utils::truncate_coordinate($_) } $lat, $lon; + my $j = mySociety::MaPit::call('nearest', "4326/$lon,$lat"); + if ($j->{postcode}) { + $closest->{postcode} = $j->{postcode}; } - return $data; + return $closest; } sub reports_body_check { |