aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/Default.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/Default.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm35
1 files changed, 17 insertions, 18 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