Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'lux/bingternational'

  • Loading branch information...
commit 5268a7dd4fb783e6b3f7b5387aa0b99708157b65 2 parents f7c4661 + 2510c64
@dracos dracos authored
View
4 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;
View
6 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;
View
13 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/';
Please sign in to comment.
Something went wrong with that request. Please try again.