aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode/OSM.pm
diff options
context:
space:
mode:
authorJon Kristensen <info@jonkri.com>2014-01-25 18:37:58 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2014-03-11 16:54:08 +0000
commit331864878a549028ceff77eb45b30cda952f26fb (patch)
treee37fc13aa289ba678d811c03b5894d20d7977f39 /perllib/FixMyStreet/Geocode/OSM.pm
parent12cbe993e2ec44fdf6e770ec70ce92f9d20e76a6 (diff)
Move Swedish changes from Geocode/OSM.pm to Geocode/FixaMinGata.pm
Diffstat (limited to 'perllib/FixMyStreet/Geocode/OSM.pm')
-rw-r--r--perllib/FixMyStreet/Geocode/OSM.pm34
1 files changed, 9 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm
index f032a97b3..fd14b0acc 100644
--- a/perllib/FixMyStreet/Geocode/OSM.pm
+++ b/perllib/FixMyStreet/Geocode/OSM.pm
@@ -10,7 +10,6 @@ package FixMyStreet::Geocode::OSM;
use warnings;
use strict;
-use Data::Dumper;
use Digest::MD5 qw(md5_hex);
use Encode;
@@ -35,19 +34,17 @@ sub string {
my $params = $c->cobrand->disambiguate_location($s);
$s = FixMyStreet::Geocode::escape($s);
- # $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i;
+ $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i;
my $url = "${nominatimbase}search?";
my %query_params = (
q => $s,
format => 'json',
- addressdetails => 1,
- limit => 20,
#'accept-language' => '',
- email => 'info' . chr(64) . 'morus.se',
+ email => 'support' . chr(64) . 'fixmystreet.com',
);
- # $query_params{viewbox} = $params->{bounds}[1] . ',' . $params->{bounds}[2] . ',' . $params->{bounds}[3] . ',' . $params->{bounds}[0]
- # if $params->{bounds};
+ $query_params{viewbox} = $params->{bounds}[1] . ',' . $params->{bounds}[2] . ',' . $params->{bounds}[3] . ',' . $params->{bounds}[0]
+ if $params->{bounds};
$query_params{countrycodes} = $params->{country}
if $params->{country};
$url .= join('&', map { "$_=$query_params{$_}" } keys %query_params);
@@ -71,34 +68,21 @@ sub string {
$js = JSON->new->utf8->allow_nonref->decode($js);
- my ( %locations, $error, @valid_locations, $latitude, $longitude );
+ my ( $error, @valid_locations, $latitude, $longitude );
foreach (@$js) {
# These co-ordinates are output as query parameters in a URL, make sure they have a "."
- next if $_->{class} eq "boundary";
-
- my @s = split(/,/, $_->{display_name});
-
- my $address = join(",", @s[0,1,2]);
-
- $locations{$address} = [$_->{lat}, $_->{lon}];
- }
-
- my ($key) = keys %locations;
-
- return { latitude => $locations{$key}[0], longitude => $locations{$key}[1] } if scalar keys %locations == 1;
- return { error => _('Sorry, we could not find that location.') } if scalar keys %locations == 0;
-
- foreach $key (keys %locations) {
- ( $latitude, $longitude ) = ($locations{$key}[0], $locations{$key}[1]);
+ ( $latitude, $longitude ) = ( $_->{lat}, $_->{lon} );
mySociety::Locale::in_gb_locale {
push (@$error, {
- address => $key,
+ address => $_->{display_name},
latitude => sprintf('%0.6f', $latitude),
longitude => sprintf('%0.6f', $longitude)
});
};
+ push (@valid_locations, $_);
}
+ return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1;
return { error => $error };
}