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,11 +140,20 @@ 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;
$self->render( if ( @candidates > 5 ) {
json => { $self->render(
candidates => [ @candidates[ 0 .. 4 ] ], json => {
} candidates => [ @candidates[ 0 .. 4 ] ],
); }
);
}
else {
$self->render(
json => {
candidates => [@candidates],
}
);
}
} }
} }