diff options
Diffstat (limited to 'perllib/FixMyStreet/Geocode/OSM.pm')
-rw-r--r-- | perllib/FixMyStreet/Geocode/OSM.pm | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index ba939b443..fd14b0acc 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -15,9 +15,10 @@ use Digest::MD5 qw(md5_hex); use Encode; use File::Slurp; use File::Path (); -use LWP::Simple; +use LWP::Simple qw($ua); use Memcached; use XML::Simple; +use mySociety::Locale; my $osmapibase = "http://www.openstreetmap.org/api/"; my $nominatimbase = "http://nominatim.openstreetmap.org/"; @@ -28,8 +29,13 @@ my $nominatimbase = "http://nominatim.openstreetmap.org/"; # 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, $c, $params ) = @_; + my ( $s, $c ) = @_; + + my $params = $c->cobrand->disambiguate_location($s); + + $s = FixMyStreet::Geocode::escape($s); $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i; + my $url = "${nominatimbase}search?"; my %query_params = ( q => $s, @@ -49,6 +55,7 @@ sub string { if (-s $cache_file) { $js = File::Slurp::read_file($cache_file); } else { + $ua->timeout(15); $js = LWP::Simple::get($url); $js = encode_utf8($js) if utf8::is_utf8($js); File::Path::mkpath($cache_dir); @@ -56,7 +63,7 @@ sub string { } if (!$js) { - return { error => _('Sorry, we could not parse that location. Please try again.') }; + return { error => _('Sorry, we could not find that location.') }; } $js = JSON->new->utf8->allow_nonref->decode($js); |