From d1c38a2bdbe5891fa63bde40e398e3cc33881566 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 23 Jun 2020 14:32:42 +0100 Subject: Improve Bing geocoder results. Add a couple of parameters to hopefully improve results, and make sure the returned locality is included in the summary address. --- perllib/FixMyStreet/Geocode/Bing.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 1d39d911f..1b947abee 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -36,6 +36,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; @@ -52,7 +54,13 @@ sub string { 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 -- cgit v1.2.3 From 7359a017d4386c96cf681bb694f207138ebf0bc9 Mon Sep 17 00:00:00 2001 From: M Somerville Date: Mon, 2 Nov 2020 11:20:12 +0000 Subject: Ignore Low Bing geocoder results if any higher. --- perllib/FixMyStreet/Geocode/Bing.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 1b947abee..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; @@ -52,6 +53,19 @@ 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}; if ($params->{bing_country}) { -- cgit v1.2.3