aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Gaze.pm
blob: bccc81d8cf741385621bad22319aa2c61873f9eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package FixMyStreet::Gaze;

use strict;
use warnings;

use mySociety::Gaze;

sub get_radius_containing_population ($$) {
    my ($lat, $lon) = @_;

    # Don't call out to a real gaze when testing.
    return 10.0 if FixMyStreet->test_mode;

    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;