diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixaMinGata.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/OSM.pm | 20 |
2 files changed, 19 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm index b631e1228..f1059086f 100644 --- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -69,6 +69,7 @@ sub geocode_postcode { # Most people write Swedish postcodes like this: #+ XXX XX, so let's remove the space # Is this the right place to do this? //Rikard + # This is the right place! // Jonas $s =~ s/\ //g; # Rikard, remove space in postcode if ($s =~ /^\d{5}$/) { my $location = mySociety::MaPit::call('postcode', $s); diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index fd14b0acc..170eb8c78 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -40,6 +40,7 @@ sub string { my %query_params = ( q => $s, format => 'json', + addressdetails => 1, #'accept-language' => '', email => 'support' . chr(64) . 'fixmystreet.com', ); @@ -71,18 +72,33 @@ sub string { 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 unless $_->{type} eq "town" || + $_->{type} eq "village" || + $_->{type} eq "city" || + $_->{type} eq "secondary" || + $_->{type} eq "tertiary" || + $_->{type} eq "primary" || + $_->{type} eq "unclassified" || + $_->{type} eq "residential"; + ( $latitude, $longitude ) = ( $_->{lat}, $_->{lon} ); mySociety::Locale::in_gb_locale { push (@$error, { - address => $_->{display_name}, + # address => ($_->{address}->{postcode})? +#($_->{address}->{road}.", ".$_->{address}->{postcode}." ".$_->{address}->{administrative}):($_->{address}->{road}.", ".$_->{address}->{administrative}) , + address => $_->{address}->{road}.", ".$_->{address}->{administrative}, latitude => sprintf('%0.6f', $latitude), longitude => sprintf('%0.6f', $longitude) }); }; + push (@valid_locations, $_); } - return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; + my %seen; + my @final_valid_locations = grep { $seen{$_->{address}}++ } @{$error}; + + return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1 or scalar keys %seen == 1; return { error => $error }; } |