diff options
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/Default.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 1e87468ac..e1bf196bd 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -576,18 +576,37 @@ Used by rss feeds to provide a bit more context =cut sub find_closest_address_for_rss { - my ( $self, $latitude, $longitude ) = @_; + my ( $self, $latitude, $longitude, $problem ) = @_; my $str = ''; - if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ) ) { - if ($j->{resourceSets}[0]{resources}[0]{name}) { - my $address = $j->{resourceSets}[0]{resources}[0]{address}; - my @address; - push @address, $address->{addressLine} if $address->{addressLine} ne 'Street'; - push @address, $address->{locality}; - $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), - join( ', ', @address ) ); - } + my $j; + if ( $problem && ref($problem) =~ /FixMyStreet/ && $problem->can( 'geocode' ) ) { + $j = $problem->geocode; + } else { + $problem = FixMyStreet::App->model('DB::Problem')->find( { id => $problem->{id} } ); + $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, 1 ); + + # # FIXME: work out why this does not work - see populate bing script for details + # # bad data here + # $j->{copyright} = ''; + + # $problem->geocode( $j ); + # $problem->update; + # } + + if ($j && $j->{resourceSets}[0]{resources}[0]{name}) { + my $address = $j->{resourceSets}[0]{resources}[0]{address}; + my @address; + push @address, $address->{addressLine} if $address->{addressLine} ne 'Street'; + push @address, $address->{locality}; + $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"), + join( ', ', @address ) ); } return $str; |