diff options
author | Struan Donald <struan@exo.org.uk> | 2017-12-22 12:53:48 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-09 12:57:56 +0100 |
commit | 22f0fed0b1ce6e7effac37e025bd55dc6043a838 (patch) | |
tree | a4bd66224c560418863319e9a6144d9b8702d462 /perllib/FixMyStreet/App/Controller/Around.pm | |
parent | 22815e994510659870987609d244b3f6324bab22 (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/App/Controller/Around.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 25f97fd8f..8fed5c3aa 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -308,6 +308,27 @@ sub ajax : Path('/ajax') { $c->forward('/reports/ajax', [ 'around/on_map_list_items.html' ]); } +sub location_closest_address : Path('/ajax/closest') { + my ( $self, $c ) = @_; + $c->res->content_type('application/json; charset=utf-8'); + + my $lat = $c->get_param('lat'); + my $lon = $c->get_param('lon'); + unless ($lat && $lon) { + $c->res->status(404); + $c->res->body(''); + return; + } + + my $closest = $c->cobrand->find_closest({ latitude => $lat, longitude => $lon }); + my $data = { + road => $closest->{address}{addressLine}, + full_address => $closest->{name}, + }; + + $c->res->body(encode_json($data)); +} + sub location_autocomplete : Path('/ajax/geocode') { my ( $self, $c ) = @_; $c->res->content_type('application/json; charset=utf-8'); |