From 0e83d3541eece4481bd6ad66eaffd9e6625d8137 Mon Sep 17 00:00:00 2001 From: Guillaume RISCHARD Date: Thu, 22 Mar 2012 12:06:05 +0100 Subject: International support for Bing geocoding --- perllib/FixMyStreet/Geocode/Bing.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 856d7061e..4045371a5 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -23,10 +23,11 @@ use Digest::MD5 qw(md5_hex); sub string { my ( $s, $c, $params ) = @_; $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i; - my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s&c=en-GB"; # FIXME nb-NO for Norway + my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s"; $url .= '&mapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] if $params->{bounds}; $url .= '&userLocation=' . $params->{centre} if $params->{centre}; + $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; my $cache_file = $cache_dir . md5_hex($url); @@ -43,7 +44,7 @@ sub string { if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; - } elsif ($js =~ /BT\d/) { + } elsif ($js =~ /BT\d/ && $params->{bing_country} eq 'United Kingdom') { return { error => _("We do not currently cover Northern Ireland, I'm afraid.") }; } @@ -54,9 +55,10 @@ sub string { my $results = $js->{resourceSets}->[0]->{resources}; my ( $error, @valid_locations, $latitude, $longitude ); + foreach (@$results) { my $address = $_->{name}; - next unless $_->{address}->{countryRegion} eq 'United Kingdom'; # FIXME This is UK only + next unless $_->{address}->{countryRegion} eq $params->{bing_country}; ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); push (@valid_locations, $_); @@ -71,7 +73,8 @@ sub reverse { # Get nearest road-type thing from Bing my $key = mySociety::Config::get('BING_MAPS_API_KEY', ''); if ($key) { - my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=$key"; + my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key"; + $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; my $j; if ( $cache ) { my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; -- cgit v1.2.3 From 2510c64411a437f293dcaf36086618660db5d860 Mon Sep 17 00:00:00 2001 From: Guillaume RISCHARD Date: Thu, 22 Mar 2012 13:16:06 +0100 Subject: Reverse bing geocoding should get the local culture parameter --- perllib/FixMyStreet/Geocode/Bing.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 4045371a5..70275c2c7 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -68,13 +68,13 @@ sub string { } sub reverse { - my ( $latitude, $longitude, $cache ) = @_; + my ( $latitude, $longitude, $bing_culture, $cache ) = @_; # Get nearest road-type thing from Bing my $key = mySociety::Config::get('BING_MAPS_API_KEY', ''); if ($key) { my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key"; - $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; + $url .= '&c=' . $bing_culture if $bing_culture; my $j; if ( $cache ) { my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; -- cgit v1.2.3 From e2cc014a4dc1728d78cbf8e076f1a15645d1e6e7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 22 Mar 2012 13:13:26 +0000 Subject: Initial creation of Bromley cobrand. --- perllib/FixMyStreet/Geocode/Bing.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 70275c2c7..f00cf9671 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -24,7 +24,7 @@ sub string { my ( $s, $c, $params ) = @_; $s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i; my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s"; - $url .= '&mapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] + $url .= '&userMapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] if $params->{bounds}; $url .= '&userLocation=' . $params->{centre} if $params->{centre}; $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; -- cgit v1.2.3 From 8454ac8ce05202b21e1f46e99cbc729cc5cd5853 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 28 Mar 2012 11:24:20 +0100 Subject: Ignore some 'duplicate' results in geocoding. --- perllib/FixMyStreet/Geocode/Bing.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index f00cf9671..83fde0c2c 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -59,10 +59,18 @@ sub string { foreach (@$results) { my $address = $_->{name}; next unless $_->{address}->{countryRegion} eq $params->{bing_country}; + + # Getting duplicate, yet different, results from Bing sometimes + next if @valid_locations + && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode} + && ( $valid_locations[-1]{address}{locality} eq $_->{address}{adminDistrict2} + || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality} ); + ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); push (@valid_locations, $_); } + return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; return { error => $error }; } -- cgit v1.2.3 From d3159038445f2b78915abfbe4ec07fcd99cedf06 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 29 Mar 2012 12:35:47 +0100 Subject: Also treat as same if just same locality and postalcode. --- perllib/FixMyStreet/Geocode/Bing.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 83fde0c2c..99197a5f9 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -64,7 +64,9 @@ sub string { next if @valid_locations && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode} && ( $valid_locations[-1]{address}{locality} eq $_->{address}{adminDistrict2} - || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality} ); + || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality} + || $valid_locations[-1]{address}{locality} eq $_->{address}{locality} + ); ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); -- cgit v1.2.3 From 435b09e7b908afa224a6e972c33379fb6c756b1f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 30 Mar 2012 17:34:01 +0100 Subject: Make sure postalCode is present in result. --- perllib/FixMyStreet/Geocode/Bing.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 99197a5f9..4ba00dbfe 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -62,7 +62,7 @@ sub string { # Getting duplicate, yet different, results from Bing sometimes next if @valid_locations - && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode} + && $_->{address}{postalCode} && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode} && ( $valid_locations[-1]{address}{locality} eq $_->{address}{adminDistrict2} || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality} || $valid_locations[-1]{address}{locality} eq $_->{address}{locality} -- cgit v1.2.3 From 79c777f2a6e3cd49f227f0ba1feb8f7c5b97fd10 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 4 May 2012 15:17:29 +0100 Subject: Fix bug wherein links on multiple result pages in other locales would not work. --- perllib/FixMyStreet/Geocode/Bing.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Geocode/Bing.pm') diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 4ba00dbfe..a24f7c102 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -69,7 +69,14 @@ sub string { ); ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; - push (@$error, { address => $address, latitude => $latitude, longitude => $longitude }); + # These co-ordinates are output as query parameters in a URL, make sure they have a "." + mySociety::Locale::in_gb_locale { + push (@$error, { + address => $address, + latitude => sprintf('%0.6f', $latitude), + longitude => sprintf('%0.6f', $longitude) + }); + }; push (@valid_locations, $_); } -- cgit v1.2.3