diff options
author | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
commit | 09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch) | |
tree | 7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/FixMyStreet/Geocode | |
parent | 585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff) | |
parent | cea89fb87a96943708a1db0f646492fbfaaf000f (diff) |
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/Geocode')
-rw-r--r-- | perllib/FixMyStreet/Geocode/Bing.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/OSM.pm | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 1d39d911f..8c5366d3d 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -7,6 +7,7 @@ package FixMyStreet::Geocode::Bing; use strict; +use warnings; use FixMyStreet::Geocode; use Utils; @@ -36,6 +37,8 @@ sub string { $url .= '&userMapView=' . join(',', @{$params->{bounds}}) if $params->{bounds}; $url .= '&userLocation=' . $params->{centre} if $params->{centre}; + $url .= '&userIp=127.0.0.1'; # So server location does not affect results + $url .= '&maxResults=10'; # Match what is said in the front end $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; $c->stash->{geocoder_url} = $url; @@ -50,9 +53,28 @@ sub string { my $results = $js->{resourceSets}->[0]->{resources}; my ( $error, @valid_locations, $latitude, $longitude ); + # If there are any High/Medium confidence results, don't include Low ones + my $exclude_low; + foreach (@$results) { + my $confidence = $_->{confidence}; + if ($confidence eq 'High' || $confidence eq 'Medium') { + $exclude_low = 1; + last; + } + } + if ($exclude_low) { + @$results = grep { $_->{confidence} ne 'Low' } @$results; + } + foreach (@$results) { my $address = $_->{name}; - next if $params->{bing_country} && $_->{address}->{countryRegion} ne $params->{bing_country}; + if ($params->{bing_country}) { + next if $_->{address}->{countryRegion} ne $params->{bing_country}; + $address =~ s/, $params->{bing_country}$//; + } + if ($address !~ /$_->{address}->{locality}/) { + $address .= ", $_->{address}->{locality}"; + } # Getting duplicate, yet different, results from Bing sometimes next if @valid_locations diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index 20e653cf6..06162d74c 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -45,6 +45,7 @@ sub string { if $params->{bounds}; $query_params{countrycodes} = $params->{country} if $params->{country}; + $c->cobrand->call_hook(geocoder_munge_query_params => \%query_params); $url .= join('&', map { "$_=$query_params{$_}" } sort keys %query_params); $c->stash->{geocoder_url} = $url; |