From 7b0d984bd9607e5b7e12184f1d91bc52a0280417 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 24 May 2011 13:14:45 +0100 Subject: google maps don't seem to pay as much attention to region hinting as they once did so make sure we add UK on to the end. also update tests to take into account changed results because of this. --- perllib/FixMyStreet/Geocode.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') 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); -- cgit v1.2.3 From a6c11ec2e1fa29ffc28fed8fa0102f2fb9d61845 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Jun 2011 11:15:01 +0100 Subject: Get rid of some more fake_q etc. --- perllib/FixMyStreet/Geocode.pm | 64 ++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 37 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index cbfa3c4e7..9419a91f7 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -38,14 +38,14 @@ BEGIN { # Northern Ireland). The information in the query may be used by cobranded versions # of the site to diambiguate locations. sub lookup { - my ($s, $q) = @_; + my ($s, $c) = @_; my ($latitude, $longitude, $error); if (mySociety::Config::get('COUNTRY') eq 'GB') { if ($s =~ /^\d+$/) { $error = 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.'; } elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) { my $location = mySociety::MaPit::call('postcode', $s); - unless ($error = Page::mapit_check_error($location)) { + unless ($error = mapit_check_error($location)) { $latitude = $location->{wgs84_lat}; $longitude = $location->{wgs84_lon}; } @@ -53,20 +53,20 @@ sub lookup { } elsif (mySociety::Config::get('COUNTRY') eq 'NO') { if ($s =~ /^\d{4}$/) { my $location = mySociety::MaPit::call('postcode', $s); - unless ($error = Page::mapit_check_error($location)) { + unless ($error = mapit_check_error($location)) { $latitude = $location->{wgs84_lat}; $longitude = $location->{wgs84_lon}; } } } unless ($error || defined $latitude) { - ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $q); + ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $c); } return ($latitude, $longitude, $error); } sub geocoded_string_coordinates { - my ($js, $q) = @_; + my ( $js ) = @_; my ($latitude, $longitude, $error); my ($accuracy) = $js =~ /"Accuracy" *: *(\d)/; if ($accuracy < 4) { @@ -89,18 +89,18 @@ sub geocoded_string_coordinates { } sub results_check { - my $q = shift; + my $c = shift; my ($error, @valid_locations); foreach (@_) { next unless /"address" *: *"(.*?)"/s; my $address = $1; - next unless Cobrand::geocoded_string_check(Page::get_cobrand($q), $address, $q); + next unless $c->cobrand->geocoded_string_check( $address ); next if $address =~ /BT\d/; push (@$error, $address); push (@valid_locations, $_); } if (scalar @valid_locations == 1) { - return geocoded_string_coordinates($valid_locations[0], $q); + return geocoded_string_coordinates( $valid_locations[0] ); } $error = _('Sorry, we could not find that location.') unless $error; return (undef, undef, $error); @@ -112,12 +112,12 @@ sub results_check { # an array of matches if there are more than one. The information in the query # may be used to disambiguate the location in cobranded versions of the site. sub string { - my ($s, $q) = @_; + my ($s, $c) = @_; $s = lc($s); $s =~ s/[^-&\w ']/ /g; $s =~ s/\s+/ /g; $s = URI::Escape::uri_escape_utf8($s); - $s = Cobrand::disambiguate_location(Page::get_cobrand($q), "q=$s", $q); + $s = $c->cobrand->disambiguate_location( "q=$s" ); $s =~ s/%20/+/g; my $url = 'http://maps.google.com/maps/geo?' . $s; my $cache_dir = mySociety::Config::get('GEO_CACHE'); @@ -151,42 +151,32 @@ sub string { } elsif ($js !~ /"code" *: *200/) { $error = _('Sorry, we could not find that location.'); } elsif ($js =~ /}, *{/) { # Multiple - return results_check($q, (split /}, *{/, $js)); + return results_check($c, (split /}, *{/, $js)); } elsif ($js =~ /BT\d/) { # Northern Ireland, hopefully $error = _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region."); } else { - return results_check($q, $js); + return results_check($c, $js); } return (undef, undef, $error); } -# list_choices -# Prints response if there's more than one possible result -sub list_choices { - my ($choices, $page, $q) = @_; - my $url; - my $cobrand = Page::get_cobrand($q); - my $message = _('We found more than one match for that location. We show up to ten matches, please try a different search if yours is not here.'); - my $out = '

' . $message . '

'; - my $choice_list = ''; - $out .= $choice_list; - my %vars = (message => $message, - choice_list => $choice_list, - header => _('More than one match'), - url_home => Cobrand::url($cobrand, '/', $q)); - my $cobrand_choice = Page::template_include('geocode-choice', $q, Page::template_root($q), %vars); - return $cobrand_choice if $cobrand_choice; - return $out; + if (mySociety::Config::get('COUNTRY') eq 'GB') { + my $island = $location->{coordsyst}; + if (!$island) { + return _("Sorry, that appears to be a Crown dependency postcode, which we don't cover."); + } + if ($island eq 'I') { + return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region."); + } + } + return 0; } 1; -- cgit v1.2.3 From b5a218792a7bcf477c930205b6a7c341a90d3efd Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jun 2011 17:26:01 +0100 Subject: Final bits of Page.pm gone. --- perllib/FixMyStreet/Geocode.pm | 1 - 1 file changed, 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 9419a91f7..50a7ba339 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -18,7 +18,6 @@ use Digest::MD5 qw(md5_hex); use URI::Escape; use Cobrand; -use Page; use Utils; use mySociety::Config; use mySociety::Locale; -- cgit v1.2.3 From 614abaa627d3f9dfe14efcb994cdcfc0146a623d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jun 2011 23:55:54 +0100 Subject: Removal of old Cobrand.pm and last . --- perllib/FixMyStreet/Geocode.pm | 1 - 1 file changed, 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 50a7ba339..a520a2daa 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -17,7 +17,6 @@ use LWP::Simple; use Digest::MD5 qw(md5_hex); use URI::Escape; -use Cobrand; use Utils; use mySociety::Config; use mySociety::Locale; -- cgit v1.2.3