diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-04-22 16:48:57 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-05-18 12:57:52 +0100 |
commit | 1a1bfff12415a7793fee22bcd4e5e39e10dbd4d3 (patch) | |
tree | 6313f583e4e278ad3fb2885b8bd0493bd429b23c /perllib/FixMyStreet/Gaze.pm | |
parent | 66d93ceaed9df6ff3e0e28a62e655ad769c99614 (diff) |
Fallback if request to Gaze fails.
Fixes #1286.
Diffstat (limited to 'perllib/FixMyStreet/Gaze.pm')
-rw-r--r-- | perllib/FixMyStreet/Gaze.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Gaze.pm b/perllib/FixMyStreet/Gaze.pm new file mode 100644 index 000000000..a072cd246 --- /dev/null +++ b/perllib/FixMyStreet/Gaze.pm @@ -0,0 +1,24 @@ +package FixMyStreet::Gaze; + +use strict; +use warnings; + +use mySociety::Gaze; + +sub get_radius_containing_population ($$) { + my ($lat, $lon) = @_; + + my $dist = eval { + mySociety::Locale::in_gb_locale { + mySociety::Gaze::get_radius_containing_population($lat, $lon, 200_000); + }; + }; + if ($@) { + # Error fetching from gaze, let's fall back to 10km + $dist = 10; + } + $dist = int( $dist * 10 + 0.5 ) / 10.0; + return $dist; +} + +1; |