aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
committerMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
commita27ce1524d801d2742a2bdb6ec1da45126d64353 (patch)
tree64123c4e17dc1776aa0a7cd65ee01d49d3e7d978 /perllib/FixMyStreet/Geocode.pm
parent377bd96aab7cad3434185c30eb908c9da447fe40 (diff)
parent2773c60226b9370fe8ee00f7b205b571bb87c3b5 (diff)
Merge tag 'v3.0.1' into fiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/Geocode.pm')
-rw-r--r--perllib/FixMyStreet/Geocode.pm25
1 files changed, 15 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index d552afaa5..61c968269 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -13,12 +13,14 @@ use JSON::MaybeXS;
use LWP::Simple qw($ua);
use Path::Tiny;
use URI::Escape;
-use FixMyStreet::Geocode::Bing;
-use FixMyStreet::Geocode::Google;
-use FixMyStreet::Geocode::OSM;
-use FixMyStreet::Geocode::Zurich;
use Utils;
+use Module::Pluggable
+ sub_name => 'geocoders',
+ search_path => __PACKAGE__,
+ require => 1,
+ except => qr/Address/;
+
# lookup STRING CONTEXT
# Given a user-inputted string, try and convert it into co-ordinates using either
# MaPit if it's a postcode, or some web API otherwise. Returns an array of
@@ -44,14 +46,17 @@ sub lookup {
sub string {
my ($s, $c) = @_;
- my $service = $c->cobrand->get_geocoder($c);
+ my $service = $c->cobrand->get_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);
+ $service = __PACKAGE__ . '::' . $service;
+ my %avail = map { $_ => 1 } __PACKAGE__->geocoders;
+
+ if (!$avail{$service} || ($service->can('setup') && !$service->setup)) {
+ $service = __PACKAGE__ . '::OSM';
+ }
+
+ return $service->string($s, $c);
}
# escape STRING CONTEXT