summaryrefslogtreecommitdiff
path: root/bin/hafas-m
diff options
context:
space:
mode:
authorDerf Null <derf@finalrewind.org>2023-04-07 14:49:32 +0200
committerDerf Null <derf@finalrewind.org>2023-04-07 14:49:32 +0200
commit915bad108d838716c17ac605d13d59624b2bc539 (patch)
tree2157b0a02a17359c98e18978e0a1b705771b81ba /bin/hafas-m
parent809f1910da538bffb0e671eb3965f28d5e60237a (diff)
add geoSearch mode
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-xbin/hafas-m21
1 files changed, 19 insertions, 2 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 2b6c2d0..53f232b 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -59,7 +59,14 @@ my %opt = (
service => $service,
);
-if ( $opt{station} =~ m{[|]} ) {
+if ( $opt{station} =~ m{ ^ (?<lat> [0-9.]+ ) : (?<lon> [0-9].+ ) $ }x ) {
+ $opt{geoSearch} = {
+ lat => $+{lat},
+ lon => $+{lon},
+ };
+ delete $opt{station};
+}
+elsif ( $opt{station} =~ m{[|]} ) {
$opt{journey} = { id => $opt{station} };
delete $opt{station};
}
@@ -234,7 +241,17 @@ if ( my $err = $status->errstr ) {
exit 2;
}
-if ( $opt{journey} ) {
+if ( $opt{geoSearch} ) {
+ for my $result ( $status->results ) {
+ printf(
+ "%5.1f km %8d %s\n",
+ $result->{distance_m} * 1e-3,
+ $result->{eva}, $result->{name}
+ );
+ }
+ exit 0;
+}
+elsif ( $opt{journey} ) {
my $result = $status->result;
printf( "%s → %s", $result->name, $result->route_end );