aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode/Address.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2017-12-22 12:53:48 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-09 12:57:56 +0100
commit22f0fed0b1ce6e7effac37e025bd55dc6043a838 (patch)
treea4bd66224c560418863319e9a6144d9b8702d462 /perllib/FixMyStreet/Geocode/Address.pm
parent22815e994510659870987609d244b3f6324bab22 (diff)
ajax endpoint to return closest address.
/ajax/closest will return ajax with details of the closest address to the lat/lon passed in from the Bing geocoder. Tidy up find_closest() to use overloaded string rather than passing in whether you want a string or not.
Diffstat (limited to 'perllib/FixMyStreet/Geocode/Address.pm')
-rw-r--r--perllib/FixMyStreet/Geocode/Address.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Geocode/Address.pm b/perllib/FixMyStreet/Geocode/Address.pm
new file mode 100644
index 000000000..522091f62
--- /dev/null
+++ b/perllib/FixMyStreet/Geocode/Address.pm
@@ -0,0 +1,28 @@
+package FixMyStreet::Geocode::Address;
+
+use strict;
+use warnings;
+
+use overload '""' => \&as_string, fallback => 1;
+
+sub new {
+ my ($class, $data) = @_;
+ my $self = { %$data };
+ bless $self, $class;
+}
+
+sub as_string {
+ my $self = shift;
+
+ my $data = sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"),
+ $self->{name}) . "\n\n";
+
+ if ($self->{postcode}) {
+ $data .= sprintf(_("Nearest postcode to the pin placed on the map (automatically generated): %s (%sm away)"),
+ $self->{postcode}{postcode}, $self->{postcode}{distance}) . "\n\n";
+ }
+
+ return $data;
+}
+
+1;