Fix invalid geolocation list when less than 5 unique station names are nearby

This issue was introduced in 7c7b5e9f95 and
caused the client-side javascript code to crash
This commit is contained in:
Daniel Friesel 2019-10-19 16:47:33 +02:00
parent 780cdafcf5
commit 4ba82b51d3

View file

@ -140,12 +140,21 @@ sub geolocation {
} Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon,
$lat, 10 ); $lat, 10 );
@candidates = uniq_by { $_->{name} } @candidates; @candidates = uniq_by { $_->{name} } @candidates;
if ( @candidates > 5 ) {
$self->render( $self->render(
json => { json => {
candidates => [ @candidates[ 0 .. 4 ] ], candidates => [ @candidates[ 0 .. 4 ] ],
} }
); );
} }
else {
$self->render(
json => {
candidates => [@candidates],
}
);
}
}
} }
sub log_action { sub log_action {