aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode/Google.pm
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2018-01-24 18:01:56 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-02-12 16:17:25 +0000
commit7ec0d3f67766764967a8bb92099c582f8bd6aaf5 (patch)
tree2e9da126c8a3ea7994e43c1c693e5aa489b687c6 /perllib/FixMyStreet/Geocode/Google.pm
parent27027ad882f5e1ddb8f2445e3b63972524ba82aa (diff)
Cobrands can pass `components` to Google Geocoder.
This allows more fine grained control over the geocoder search, e.g. to specify the administrative area or town. See the geocoder api docs: https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
Diffstat (limited to 'perllib/FixMyStreet/Geocode/Google.pm')
-rw-r--r--perllib/FixMyStreet/Geocode/Google.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm
index e64d02c4c..162101953 100644
--- a/perllib/FixMyStreet/Geocode/Google.pm
+++ b/perllib/FixMyStreet/Geocode/Google.pm
@@ -8,6 +8,7 @@ package FixMyStreet::Geocode::Google;
use strict;
use Utils;
+use URI::Escape;
# string STRING CONTEXT
# Looks up on Google Maps API, and caches, a user-inputted location.
@@ -19,11 +20,13 @@ sub string {
my $params = $c->cobrand->disambiguate_location($s);
+ my $components = "";
+
# For some reason adding gl=uk is no longer sufficient to make google
- # think we are in the UK for some locations so we explictly add UK to
- # the address.
- if ($c->cobrand->country eq 'GB' && $s !~ /, *UK/ && $s !~ /united *kingdom$/) {
- $s .= ', UK';
+ # think we are in the UK for some locations so we explicitly tell Google
+ # the country.
+ if ($c->cobrand->country eq 'GB') {
+ $components = "country:GB";
}
$s = FixMyStreet::Geocode::escape($s);
@@ -37,8 +40,13 @@ sub string {
} elsif ($params->{country}) {
$url .= '&region=' . $params->{country};
}
+ if ($params->{components}) {
+ $components .= ($components ? '|' : '') . URI::Escape::uri_escape_utf8($params->{components});
+ }
$url .= '&language=' . $params->{lang} if $params->{lang};
+ $url .= '&components=' . $components if $components;
+
my $args = 'key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY');
my $js = FixMyStreet::Geocode::cache('google', $url, $args, qr/"status"\s*:\s*"(OVER_QUERY_LIMIT|REQUEST_DENIED|INVALID_REQUEST|UNKNOWN_ERROR)"/);
if (!$js) {