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

db-iris: turn lat:lon lookup into a proper, intended feature

parent f271d608
Loading
Loading
Loading
Loading
+18 −24
Original line number Diff line number Diff line
@@ -66,6 +66,22 @@ if ( @ARGV != 1 ) {
@grep_type     = split( qr{,}, join( q{,}, @grep_type ) );

my ($station) = @ARGV;

if ( $station =~ m{ ^ (?<lat> \d+ [.]? \d* ) : (?<lon> \d+ [.]? \d* ) $ }x ) {
	my @candidates
	  = Travel::Status::DE::IRIS::Stations::get_station_by_location( $+{lon},
		$+{lat} );
	for my $candidate (@candidates) {
		printf(
			"%5.1f km  %-7s %s\n",
			$candidate->[1],
			$candidate->[0][0],
			$candidate->[0][1],
		);
	}
	exit(0);
}

$station = get_station($station);

if ($track_via) {
@@ -204,30 +220,6 @@ sub get_station {
		return $input_name;
	}

	if ( $input_name
		=~ m{ ^ (?<lon> [[:digit:].]+ ) , (?<lat> [[:digit:].]+ ) }x )
	{
		my @candidates
		  = Travel::Status::DE::IRIS::Stations::get_station_by_location(
			$+{lon}, $+{lat} );

		if ( not @candidates ) {
			say STDERR
			  "Found no stations inside a 70km radius around $+{lon},$+{lat}";
			exit(1);
		}

		say STDERR "Geolocation candidates for $+{lon},$+{lat} are:";
		say STDERR join(
			"\n",
			map {
				sprintf( "%-30s %-5s  %4.1fkm",
					$_->[0][1], $_->[0][0], $_->[1] )
			} @candidates
		);
		exit(1);
	}

	my @stations = Travel::Status::DE::IRIS::Stations::get_station($input_name);

	if ( @stations == 0 ) {
@@ -585,6 +577,8 @@ db-iris - Interface to the DeutscheBahn online departure monitor
B<db-iris> [B<-rx>] [B<-d> I<date>] [B<-o> I<output-flags>]
[B<-t> I<time>] [B<-v>|B<-V> I<via>] [I<other options ...>] I<station>

B<db-iris> I<lat>:I<lon>

=head1 VERSION

version 2.04