aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Geocode.pm16
-rwxr-xr-xt/Page.t4
-rw-r--r--t/app/controller/around.t13
3 files changed, 24 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index c06c3bb55..cbfa3c4e7 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -126,8 +126,20 @@ sub string {
if (-s $cache_file) {
$js = File::Slurp::read_file($cache_file);
} else {
- $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i
- || mySociety::Config::get('COUNTRY') ne 'GB';
+ # For some reason adding gl=uk is no longer sufficient to make google
+ # think we are in the UK for some locations so we explictly add UK to
+ # the address. We do it here so as not to invalidate existing cache
+ # entries
+ if ( mySociety::Config::get('COUNTRY') eq 'GB'
+ && $url !~ /,\+UK/
+ && $url !~ /united\++kingdom$/ )
+ {
+ if ( $url =~ /&/ ) {
+ $url =~ s/&/,+UK&/;
+ } else {
+ $url .= ',+UK';
+ }
+ }
$url .= '&sensor=false&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY');
$js = LWP::Simple::get($url);
$js = encode_utf8($js) if utf8::is_utf8($js);
diff --git a/t/Page.t b/t/Page.t
index a1ae7f3aa..20af92590 100755
--- a/t/Page.t
+++ b/t/Page.t
@@ -43,8 +43,8 @@ sub test_geocode_string() {
# geocode a straightforward string, expect success
my ( $latitude, $longitude, $error ) =
FixMyStreet::Geocode::string( 'Buckingham Palace', $q );
- is( $latitude, 51.5013639, 'example easting generated' );
- is( $longitude, -0.1418898, 'example northing generated' );
+ is( $latitude, 51.4949261, 'example easting generated' );
+ is( $longitude, -0.1461924, 'example northing generated' );
is( $error, undef, 'should not generate error for simple example' );
# expect a failure message for Northern Ireland
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 069ec605a..12b26cec7 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -43,19 +43,22 @@ foreach my $test (
{
pc => 'glenthorpe',
errors => [],
- pc_alternatives => [ # TODO - should filter out these non-UK addresses
+ pc_alternatives => [
'Glenthorpe Crescent, Leeds LS9 7',
'Glenthorpe Rd, Merton, Greater London SM4 4',
- 'Glenthorpe Ln, Katy, TX 77494, USA',
- 'Glenthorpe Dr, Walnut, CA 91789, USA',
'Glenthorpe Ave, Leeds LS9 7',
- 'Glenthorpe Ct, Katy, TX 77494, USA',
+ 'Glenthorne Rd, Hammersmith, Greater London W6 0',
+ 'Glenthorne Ave, Yeovil, Somerset BA21 4',
+ 'Glenthorne Rd, Kenwyn, Cornwall TR3 6',
+ 'Glenthorne Dr, Cheslyn Hay, Staffordshire WS6 7',
+ 'Glenthorne Gardens, Ilford, Greater London IG5 0',
+ 'Glenthorne Ave, Croydon, Greater London CR0 7',
],
},
{
pc => 'Glenthorpe Ct, Katy, TX 77494, USA',
errors =>
- ['We had a problem with the supplied co-ordinates - outside the UK?'],
+ ['Sorry, we could not find that location.'],
pc_alternatives => [],
},
)