diff options
Diffstat (limited to 'bin/send-reports')
-rwxr-xr-x | bin/send-reports | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/bin/send-reports b/bin/send-reports index 297cdf4ec..6fc1f74ec 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -18,6 +18,8 @@ use lib "$FindBin::Bin/../commonlib/perllib"; use Encode; use Error qw(:try); use File::Slurp; +use JSON; +use LWP::Simple; use CGI; # Trying awkward kludge use CronFns; @@ -97,9 +99,8 @@ foreach my $row (@$unsent) { $h{fuzzy} = $row->{used_map} ? _('To view a map of the precise location of this issue') : _('The user could not locate the problem on a map, but to see the area around the location they entered'); $h{closest_address} = ''; - $h{closest_address_machine} = ''; - # If we are in the UK include eastings and northings + # If we are in the UK include eastings and northings, and nearest stuff $h{easting_northing} = ''; if ( mySociety::Config::get('COUNTRY') eq 'GB' ) { @@ -109,7 +110,10 @@ foreach my $row (@$unsent) { $h{easting_northing} # = "Easting: $h{easting}\n\n" # . "Northing: $h{northing}\n\n"; + + $h{closest_address} = find_closest($row, $h{latitude}, $h{longitude}); } + $h{closest_address_machine} = $h{closest_address}; my (@to, @recips, $template, $areas_info); if ($site eq 'emptyhomes') { @@ -342,3 +346,25 @@ sub post_easthants_message { return $return; } +sub find_closest { + my ($row, $latitude, $longitude) = @_; + my $str = ''; + + return unless $row->{used_map}; + + # Get nearest road-type thing from Bing + my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=" . mySociety::Config::get('BING_MAPS_API_KEY'); + my $j = LWP::Simple::get($url); + $j = JSON->new->utf8->allow_nonref->decode($j); + $str .= "Nearest road to the pin placed on the map (automatically generated by Bing Maps): $j->{resourceSets}[0]{resources}[0]{name}\n\n"; + + # Get nearest postcode from Matthew's random gazetteer (put in MaPit? Or elsewhere?) + $url = "http://gazetteer.dracos.vm.bytemark.co.uk/point/$latitude,$longitude.json"; + $j = LWP::Simple::get($url); + $j = JSON->new->utf8->allow_nonref->decode($j); + if ($j->{postcode}) { + $str .= "Nearest postcode to the pin placed on the map (automatically generated): $j->{postcode}[0] ($j->{postcode}[1]m away)\n\n"; + } + return $str; +} + |