aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-03-22 12:51:54 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-03-22 12:51:54 +0000
commit5268a7dd4fb783e6b3f7b5387aa0b99708157b65 (patch)
tree1d6acade05f10ab60ba973124be81672df8ba6a9
parentf7c46612fd1ae32e738acfc084abb674d1c1487a (diff)
parent2510c64411a437f293dcaf36086618660db5d860 (diff)
Merge remote branch 'lux/bingternational'
-rwxr-xr-xbin/populate_bing_cache4
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm6
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm13
3 files changed, 15 insertions, 8 deletions
diff --git a/bin/populate_bing_cache b/bin/populate_bing_cache
index a3bef6759..17c8911d0 100755
--- a/bin/populate_bing_cache
+++ b/bin/populate_bing_cache
@@ -9,6 +9,8 @@ use Data::Dumper;
use FixMyStreet::App;
use FixMyStreet::Geocode::Bing;
+my $bing_culture = 'en-GB';
+
my $reports = FixMyStreet::App->model('DB::Problem')->search(
{
geocode => undef,
@@ -46,7 +48,7 @@ while ( my $report = $reports->next ) {
next if $report->geocode;
my $j = FixMyStreet::Geocode::Bing::reverse( $report->latitude,
- $report->longitude );
+ $report->longitude, $bing_culture );
$report->geocode($j);
$report->update;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index aacfb5e2b..a4b7cecf2 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -239,6 +239,8 @@ Returns disambiguating information available
sub disambiguate_location {
return {
country => 'uk',
+ bing_culture => 'en-GB',
+ bing_country => 'United Kingdom'
};
}
@@ -457,7 +459,7 @@ sub find_closest {
my ( $self, $latitude, $longitude, $problem ) = @_;
my $str = '';
- if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude ) ) {
+ if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) {
# cache the bing results for use in alerts
if ( $problem ) {
$problem->geocode( $j );
@@ -504,7 +506,7 @@ sub find_closest_address_for_rss {
# if we've not cached it then we don't want to look it up in order to avoid
# hammering the bing api
# if ( !$j ) {
- # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 );
+ # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture}, 1 );
# $problem->geocode( $j );
# $problem->update;
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index 856d7061e..70275c2c7 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, $_);
@@ -66,12 +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?c=en-GB&key=$key";
+ my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key";
+ $url .= '&c=' . $bing_culture if $bing_culture;
my $j;
if ( $cache ) {
my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/';