From eb5a7dcdb44f111a5d6f480ef9bb4b796abbc79a Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 10 Feb 2011 20:31:19 +0000 Subject: Put back UK-only code for atomic nature of E/N -> lat/lon conversion, module has other UK-only code in it still and it causes error without. --- perllib/FixMyStreet/Geocode.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 0379169b8..355cd827f 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -61,6 +61,13 @@ sub geocoded_string_coordinates { } elsif ( $js =~ /"coordinates" *: *\[ *(.*?), *(.*?),/ ) { $longitude = $1; $latitude = $2; + try { + my ($easting, $northing) = mySociety::GeoUtil::wgs84_to_national_grid($latitude, $longitude, 'G'); + } catch Error::Simple with { + $error = shift; + $error = _('That location does not appear to be in Britain; please try again.') + if $error =~ /out of the area covered/; + } } return ($latitude, $longitude, $error); } -- cgit v1.2.3 From c8a9805bcb850cab7bf1c1b8c34ef5c4f22e1b73 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 11 Feb 2011 10:43:35 +0000 Subject: More EN locales. --- perllib/FixMyStreet/Geocode.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 355cd827f..9ab958cd9 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -20,6 +20,7 @@ use Cobrand; use Page; use mySociety::Config; use mySociety::GeoUtil; +use mySociety::Locale; use mySociety::MaPit; use mySociety::PostcodeUtil; use mySociety::Web qw(NewURL); @@ -62,7 +63,9 @@ sub geocoded_string_coordinates { $longitude = $1; $latitude = $2; try { - my ($easting, $northing) = mySociety::GeoUtil::wgs84_to_national_grid($latitude, $longitude, 'G'); + my ($easting, $northing) = mySociety::Locale::in_gb_locale { + mySociety::GeoUtil::wgs84_to_national_grid($latitude, $longitude, 'G'); + }; } catch Error::Simple with { $error = shift; $error = _('That location does not appear to be in Britain; please try again.') -- cgit v1.2.3 From 947f5f9d6c9c74bc5acea7fbc605b653e44f7ce7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 11 Feb 2011 11:14:20 +0000 Subject: Helper function for all latlon to OSGB36 calls. --- perllib/FixMyStreet/Geocode.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 9ab958cd9..14cedbaeb 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -18,8 +18,8 @@ use URI::Escape; use Cobrand; use Page; +use Utils; use mySociety::Config; -use mySociety::GeoUtil; use mySociety::Locale; use mySociety::MaPit; use mySociety::PostcodeUtil; @@ -63,9 +63,7 @@ sub geocoded_string_coordinates { $longitude = $1; $latitude = $2; try { - my ($easting, $northing) = mySociety::Locale::in_gb_locale { - mySociety::GeoUtil::wgs84_to_national_grid($latitude, $longitude, 'G'); - }; + my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude ); } catch Error::Simple with { $error = shift; $error = _('That location does not appear to be in Britain; please try again.') -- cgit v1.2.3 From f4a8f74ba741e5566d7e3ea0f42db542ba22b3c3 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 11 Feb 2011 14:56:50 +0000 Subject: Norway place lookup. --- perllib/FixMyStreet/Geocode.pm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 14cedbaeb..2c583311b 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -39,15 +39,18 @@ BEGIN { sub lookup { my ($s, $q) = @_; my ($latitude, $longitude, $error); - 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)) { - $latitude = $location->{wgs84_lat}; - $longitude = $location->{wgs84_lon}; + 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)) { + $latitude = $location->{wgs84_lat}; + $longitude = $location->{wgs84_lon}; + } } - } else { + } + unless ($error || defined $latitude) { ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $q); } return ($latitude, $longitude, $error); @@ -94,7 +97,8 @@ sub string { if (-s $cache_file) { $js = File::Slurp::read_file($cache_file); } else { - $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i; + $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i + || mySociety::Config::get('COUNTRY') ne 'GB'; $url .= '&sensor=false&gl=uk&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY'); $js = LWP::Simple::get($url); File::Path::mkpath($cache_dir); -- cgit v1.2.3 From d129a938cb1ccbbb04a6c65b3ec8127ce18359c7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 12 Feb 2011 00:25:15 +0000 Subject: Footer for Norway. --- perllib/FixMyStreet/Geocode.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 2c583311b..ae85aba15 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -68,6 +68,7 @@ sub geocoded_string_coordinates { try { my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude ); } catch Error::Simple with { + mySociety::Locale::pop(); # We threw exception, so it won't have happened. $error = shift; $error = _('That location does not appear to be in Britain; please try again.') if $error =~ /out of the area covered/; -- cgit v1.2.3 From 1421ac837449d153fbd517caa550d26052156a21 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 14 Feb 2011 10:58:39 +0000 Subject: Only do lat/lon->E/N check if country is GB. --- perllib/FixMyStreet/Geocode.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index ae85aba15..892077d6e 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -65,13 +65,15 @@ sub geocoded_string_coordinates { } elsif ( $js =~ /"coordinates" *: *\[ *(.*?), *(.*?),/ ) { $longitude = $1; $latitude = $2; - try { - my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude ); - } catch Error::Simple with { - mySociety::Locale::pop(); # We threw exception, so it won't have happened. - $error = shift; - $error = _('That location does not appear to be in Britain; please try again.') - if $error =~ /out of the area covered/; + if (mySociety::Config::get('COUNTRY') eq 'GB') { + try { + my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude ); + } catch Error::Simple with { + mySociety::Locale::pop(); # We threw exception, so it won't have happened. + $error = shift; + $error = _('That location does not appear to be in Britain; please try again.') + if $error =~ /out of the area covered/; + } } } return ($latitude, $longitude, $error); -- cgit v1.2.3 From befd99b8e4ae3d2f60761dc9c658f3b6d6576054 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 16 Feb 2011 19:23:48 +0000 Subject: Various encoding fixing. --- perllib/FixMyStreet/Geocode.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 892077d6e..475b2f9bc 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -9,6 +9,7 @@ package FixMyStreet::Geocode; use strict; +use Encode; use Error qw(:try); use File::Slurp; use File::Path (); @@ -87,8 +88,9 @@ sub geocoded_string_coordinates { # of the site. sub string { my ($s, $q) = @_; + $s = decode_utf8($s); $s = lc($s); - $s =~ s/[^-&0-9a-z ']/ /g; + $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); @@ -102,7 +104,7 @@ sub string { } else { $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i || mySociety::Config::get('COUNTRY') ne 'GB'; - $url .= '&sensor=false&gl=uk&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY'); + $url .= '&sensor=false&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY'); $js = LWP::Simple::get($url); File::Path::mkpath($cache_dir); File::Slurp::write_file($cache_file, $js) if $js && $js !~ /"code":6[12]0/; -- cgit v1.2.3 From 426594a49a10b8c65b2b23b9952bb2866cace01b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 17 Feb 2011 13:45:32 +0000 Subject: Hopefully mostly fix charset issue (FastCGI was very unhelpful here, it turns out it auto-UTF-8 encodes sometimes without telling you. --- perllib/FixMyStreet/Geocode.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perllib/FixMyStreet/Geocode.pm') diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 475b2f9bc..17a4d8539 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -147,6 +147,7 @@ sub list_choices { my $out = '

' . $message . '

'; my $choice_list = '
    '; foreach my $choice (@$choices) { + $choice = decode_utf8($choice); $choice =~ s/, United Kingdom//; $choice =~ s/, UK//; $url = Cobrand::url($cobrand, NewURL($q, -retain => 1, -url => $page, 'pc' => $choice), $q); -- cgit v1.2.3