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.pm52
1 files changed, 24 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index ac70fff08..ad84bd496 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -509,27 +509,35 @@ sub geocoded_string_check { return 1; }
=head2 find_closest
-Used by send-reports to attach nearest things to the bottom of the report
+Used by send-reports and similar to attach nearest things to the bottom of the
+report.
=cut
sub find_closest {
- my ( $self, $latitude, $longitude, $problem ) = @_;
- my $str = '';
+ my ( $self, $problem, $as_data ) = @_;
- if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) {
+ my $j = $problem->geocode;
+ if (!$j) {
+ $j = FixMyStreet::Geocode::Bing::reverse( $problem->latitude, $problem->longitude,
+ disambiguate_location()->{bing_culture} );
# cache the bing results for use in alerts
- if ( $problem ) {
- $problem->geocode( $j );
- $problem->update;
- }
- if ($j->{resourceSets}[0]{resources}[0]{name}) {
- $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"),
- $j->{resourceSets}[0]{resources}[0]{name}) . "\n\n";
+ $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";
}
}
- return $str;
+ return $data;
}
=head2 find_closest_address_for_rss
@@ -539,26 +547,14 @@ Used by rss feeds to provide a bit more context
=cut
sub find_closest_address_for_rss {
- my ( $self, $latitude, $longitude, $problem ) = @_;
- my $str = '';
+ my ( $self, $problem ) = @_;
- my $j;
- if ( $problem && ref($problem) =~ /FixMyStreet/ && $problem->can( 'geocode' ) ) {
- $j = $problem->geocode;
- } else {
+ if (ref($problem) eq 'HASH') {
$problem = FixMyStreet::App->model('DB::Problem')->find( { id => $problem->{id} } );
- $j = $problem->geocode;
}
+ my $j = $problem->geocode;
- # if we've not cached it then we don't want to look it up in order to avoid
- # hammering the bing api
- # if ( !$j ) {
- # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture}, 1 );
-
- # $problem->geocode( $j );
- # $problem->update;
- # }
-
+ my $str = '';
if ($j && $j->{resourceSets}[0]{resources}[0]{name}) {
my $address = $j->{resourceSets}[0]{resources}[0]{address};
my @address;