aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-04 16:10:44 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-04 16:10:44 +0000
commit93e01b6bf2017f308b85301016f16d7e3619b314 (patch)
tree931c9168347b4fe5e33374cf3de31604b40061a5 /perllib/FixMyStreet/Geocode.pm
parent429f5b61f56519914dd38c0e62d0709d4d380dee (diff)
Add Zurich geocoder (and allow geocoder choice to be picked in config).
Diffstat (limited to 'perllib/FixMyStreet/Geocode.pm')
-rw-r--r--perllib/FixMyStreet/Geocode.pm24
1 files changed, 17 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index f92e9cc9a..6cfd960ed 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -13,6 +13,7 @@ use URI::Escape;
use FixMyStreet::Geocode::Bing;
use FixMyStreet::Geocode::Google;
use FixMyStreet::Geocode::OSM;
+use FixMyStreet::Geocode::Zurich;
# lookup STRING CONTEXT
# Given a user-inputted string, try and convert it into co-ordinates using either
@@ -33,18 +34,27 @@ sub lookup {
# Canonicalises, and then passes to some external API to look stuff up.
sub string {
my ($s, $c) = @_;
+
+ my $service = $c->config->{GEOCODER};
+ $service = $service->{type} if ref $service;
+ $service = 'OSM' unless $service =~ /^(Bing|Google|OSM|Zurich)$/;
+ $service = 'OSM' if $service eq 'Bing' && !FixMyStreet->config('BING_MAPS_API_KEY');
+ $service = "FixMyStreet::Geocode::${service}::string";
+
+ no strict 'refs';
+ return &$service($s, $c);
+}
+
+# escape STRING CONTEXT
+# Escapes string for putting in URL geocoding call
+sub escape {
+ my ($s, $c) = @_;
$s = lc($s);
$s =~ s/[^-&\w ']/ /g;
$s =~ s/\s+/ /g;
$s = URI::Escape::uri_escape_utf8($s);
$s =~ s/%20/+/g;
- my $params = $c->cobrand->disambiguate_location($s);
- return FixMyStreet::Geocode::Bing::string($s, $c, $params)
- if FixMyStreet->config('BING_MAPS_API_KEY');
- # Fall back to Google API, which allow access with and without a key
- return FixMyStreet::Geocode::Google::string($s, $c, $params)
- if FixMyStreet->config('GOOGLE_MAPS_API_KEY');
- return FixMyStreet::Geocode::OSM::string($s, $c, $params);
+ return $s;
}
1;