From 4ba82b51d301fff67728b8860d409d92cc11b352 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 19 Oct 2019 16:47:33 +0200 Subject: Fix invalid geolocation list when less than 5 unique station names are nearby This issue was introduced in 7c7b5e9f9536f70c92d66c4055090b46e26c4c11 and caused the client-side javascript code to crash --- lib/Travelynx/Controller/Traveling.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/Travelynx') diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index eebe27a..3fea24b 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -140,11 +140,20 @@ sub geolocation { } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, $lat, 10 ); @candidates = uniq_by { $_->{name} } @candidates; - $self->render( - json => { - candidates => [ @candidates[ 0 .. 4 ] ], - } - ); + if ( @candidates > 5 ) { + $self->render( + json => { + candidates => [ @candidates[ 0 .. 4 ] ], + } + ); + } + else { + $self->render( + json => { + candidates => [@candidates], + } + ); + } } } -- cgit v1.2.3