diff --git a/index.pl b/index.pl index 1becd27..2f2e46f 100755 --- a/index.pl +++ b/index.pl @@ -577,7 +577,7 @@ helper 'navbar_class' => sub { get '/' => sub { my ($self) = @_; - $self->render('landingpage'); + $self->render( 'landingpage', with_geolocation => 1 ); }; post '/action' => sub { @@ -640,6 +640,36 @@ post '/action' => sub { } }; +post '/x/geolocation' => sub { + my ($self) = @_; + + my $lon = $self->param('lon'); + my $lat = $self->param('lat'); + + if ( not $lon or not $lat ) { + $self->render( json => { error => 'Invalid lon/lat received' } ); + } + else { + my @candidates = map { + { + ds100 => $_->[0][0], + name => $_->[0][1], + eva => $_->[0][2], + lon => $_->[0][3], + lat => $_->[0][4], + distance => $_->[1], + } + } Travel::Status::DE::IRIS::Stations::get_station_by_location( $lon, + $lat, 5 ); + $self->render( + json => { + candidates => [@candidates], + } + ); + } + +}; + get '/*station' => sub { my ($self) = @_; my $station = $self->stash('station'); diff --git a/public/static/js/geolocation.js b/public/static/js/geolocation.js new file mode 100644 index 0000000..1c881e2 --- /dev/null +++ b/public/static/js/geolocation.js @@ -0,0 +1,55 @@ +$(document).ready(function() { + var prePlaceholder = $('p.geolocationhint'); + var placeholder = $('div.geolocation div.progress'); + var showError = function(header, message, code) { + prePlaceholder.remove(); + placeholder.remove(); + }; + + var processResult = function(data) { + if (data.error) { + showError('Backend-Fehler:', data.error, null); + } else if (data.candidates.length == 0) { + showError('Keine Bahnhöfe in 70km Umkreis gefunden', '', null); + } else { + resultTable = $('
Du bist gerade nicht eingecheckt.
+Stationen in der Umgebung:
+