geosearch: always query iris and hafas stops
This commit is contained in:
parent
5d330a7738
commit
654bde9278
2 changed files with 49 additions and 19 deletions
|
@ -555,9 +555,11 @@ sub geolocation {
|
||||||
|
|
||||||
if ( not $lon or not $lat ) {
|
if ( not $lon or not $lat ) {
|
||||||
$self->render( json => { error => 'Invalid lon/lat received' } );
|
$self->render( json => { error => 'Invalid lon/lat received' } );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
$self->render_later;
|
||||||
my @candidates = map {
|
|
||||||
|
my @iris = map {
|
||||||
{
|
{
|
||||||
ds100 => $_->[0][0],
|
ds100 => $_->[0][0],
|
||||||
name => $_->[0][1],
|
name => $_->[0][1],
|
||||||
|
@ -568,22 +570,49 @@ 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;
|
@iris = uniq_by { $_->{name} } @iris;
|
||||||
if ( @candidates > 5 ) {
|
if ( @iris > 5 ) {
|
||||||
|
@iris = @iris[ 0 .. 4 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
Travel::Status::DE::HAFAS->new_p(
|
||||||
|
promise => 'Mojo::Promise',
|
||||||
|
user_agent => $self->ua,
|
||||||
|
geoSearch => {
|
||||||
|
lat => $lat,
|
||||||
|
lon => $lon
|
||||||
|
}
|
||||||
|
)->then(
|
||||||
|
sub {
|
||||||
|
my ($hafas) = @_;
|
||||||
|
my @hafas = map {
|
||||||
|
{
|
||||||
|
name => $_->name,
|
||||||
|
eva => $_->eva,
|
||||||
|
distance => $_->distance_m / 1000,
|
||||||
|
hafas => 1
|
||||||
|
}
|
||||||
|
} $hafas->results;
|
||||||
|
if ( @hafas > 5 ) {
|
||||||
|
@hafas = @hafas[ 0 .. 4 ];
|
||||||
|
}
|
||||||
$self->render(
|
$self->render(
|
||||||
json => {
|
json => {
|
||||||
candidates => [ @candidates[ 0 .. 4 ] ],
|
candidates => [ @iris, @hafas ],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
)->catch(
|
||||||
|
sub {
|
||||||
|
my ($err) = @_;
|
||||||
$self->render(
|
$self->render(
|
||||||
json => {
|
json => {
|
||||||
candidates => [@candidates],
|
candidates => [@iris],
|
||||||
|
warning => $err,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
)->wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub travel_action {
|
sub travel_action {
|
||||||
|
|
|
@ -46,11 +46,12 @@ $(document).ready(function() {
|
||||||
const res = $(document.createElement('p'));
|
const res = $(document.createElement('p'));
|
||||||
$.each(data.candidates, function(i, candidate) {
|
$.each(data.candidates, function(i, candidate) {
|
||||||
|
|
||||||
const ds100 = candidate.ds100,
|
const eva = candidate.eva,
|
||||||
name = candidate.name,
|
name = candidate.name,
|
||||||
|
hafas = candidate.hafas,
|
||||||
distance = candidate.distance.toFixed(1);
|
distance = candidate.distance.toFixed(1);
|
||||||
|
|
||||||
const node = $('<a class="tablerow" href="/s/' + ds100 + '"><span>' + name + '</span></a>');
|
const node = $('<a class="tablerow" href="/s/' + eva + '?hafas=' + hafas + '"><span>' + name + '</span></a>');
|
||||||
node.click(function() {
|
node.click(function() {
|
||||||
$('nav .preloader-wrapper').addClass('active');
|
$('nav .preloader-wrapper').addClass('active');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue