Commit 6c37dec8 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

geolocation playground

parent e09a676a
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
@@ -810,6 +810,28 @@ get '/_redirect' => sub {
	}
	}
};
};


get '/_auto' => sub {
	my $self = shift;

	$self->render('geolocation', with_geolocation => 1, hide_opts => 1);
};

post '/_geolocation' => sub {
	my $self = shift;

	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 {
		$self->render(json => {
			candidates => [ Travel::Status::DE::IRIS::Stations::get_stations_by_location($lon, $lat, 10) ],
		});
	}
};

app->defaults( layout => 'default' );
app->defaults( layout => 'default' );


get '/'               => \&handle_request;
get '/'               => \&handle_request;
+12 −0
Original line number Original line Diff line number Diff line
@@ -404,6 +404,18 @@ div.displaysingle div.info {
	color: #0000ff;
	color: #0000ff;
}
}


div.candidatelist a {
	display: block;
	text-decoration: none;
	color: black;
	padding: 1em;
	margin-top: 0.1em;
	margin-bottom: 0.1em;
	width: 20em;
	text-align: center;
	background-color: #dddddd;
}

div.about {
div.about {
	font-family: Sans-Serif;
	font-family: Sans-Serif;
	color: #666666;
	color: #666666;
+30 −0
Original line number Original line Diff line number Diff line
$(document).ready(function() {
	var processResult = function(data) {
		if (data.error) {
			$('div.candidatelist').text(data.error);
		} else {
			$.each(data.candidates, function(i, candidate) {

				var ds100 = candidate[0][0],
					name = candidate[0][1],
					distance = candidate[1];
				distance = distance.toFixed(1);

				var stationlink = $(document.createElement('a'));
				stationlink.attr('href', ds100);
				stationlink.text(name);
				$('div.candidatelist').append(stationlink);
			});
		}
	};

	var processLocation = function(loc) {
		$.post('/_geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude}, processResult);
	};

	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(processLocation);
	} else {
		$('div.candidatelist').text('Geolocation is not supported by your browser');
	}
});
+2 −0
Original line number Original line Diff line number Diff line
<div class="candidateheader">Nächstgelegene Stationen:</div>
<div class="candidatelist"></div>
+6 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,9 @@
	%= javascript begin
	%= javascript begin
	$(function () {  $('marquee').marquee() });
	$(function () {  $('marquee').marquee() });
	% end
	% end
	% if (stash('with_geolocation')) {
	%= javascript '/static/geolocation.js'
	% }
</head>
</head>
<body style="<%= (stash('hide_opts') ? 'margin: 0; padding: 0;' : q{}) %>">
<body style="<%= (stash('hide_opts') ? 'margin: 0; padding: 0;' : q{}) %>">


@@ -59,6 +62,9 @@ on 2015-01-02 at 07:00 CET.</div>
<p>
<p>
Alle Angaben ohne Gewähr.
Alle Angaben ohne Gewähr.
</p>
</p>
<p class="geolink">
<a href="<%= url_for('_auto')->to_abs->scheme('https') %>">Nahe gelegene Bahnhöfe suchen</a>
</p>
% }
% }