diff options
author | Jonas Oberg <jonas@morus.se> | 2012-12-04 13:53:53 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2014-03-11 16:36:22 +0000 |
commit | 7f89289b6fef0d8406099b2ddc4ed5008165df25 (patch) | |
tree | 0172e7b0edaa6a1a44a89acffffb65fbb903c0de /perllib/FixMyStreet/Geocode | |
parent | 1f30d3061722399557f492c2fe0856fb7e08269b (diff) |
Updated address search to behave better.. I think.
Diffstat (limited to 'perllib/FixMyStreet/Geocode')
-rw-r--r-- | perllib/FixMyStreet/Geocode/OSM.pm | 20 |
1 files changed, 18 insertions, 2 deletions
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 }; } |