diff options
| author | networkException <git@nwex.de> | 2025-06-09 23:31:02 +0200 |
|---|---|---|
| committer | Birte Friesel <derf@chaosdorf.de> | 2025-06-17 18:02:09 +0200 |
| commit | c1558384205424dbd23067aa8a1a718c814c5c07 (patch) | |
| tree | fa65549cf4640dcb556f6fd74dea66df1d874239 /lib | |
| parent | 866866965ac959e0cf358c1849251ffe47651485 (diff) | |
Use v2 api for trip lookup and handle variable precision encoded polyline
This patch updates the trip lookup codepath to use `api/v2/trip`,
which contains a breaking change with the precision of encoded
polylines, making it depend on a json value returned by the api.
See https://github.com/motis-project/motis/commit/cdca7497b0f5a8a23a6f05a3ea64fe59f199cd0a
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Travel/Status/MOTIS.pm | 2 | ||||
| -rw-r--r-- | lib/Travel/Status/MOTIS/Polyline.pm | 13 | ||||
| -rw-r--r-- | lib/Travel/Status/MOTIS/Trip.pm | 2 |
3 files changed, 10 insertions, 7 deletions
diff --git a/lib/Travel/Status/MOTIS.pm b/lib/Travel/Status/MOTIS.pm index 7559d8f..e6d0d03 100644 --- a/lib/Travel/Status/MOTIS.pm +++ b/lib/Travel/Status/MOTIS.pm @@ -83,7 +83,7 @@ sub new { ); } elsif ( my $trip_id = $conf{trip_id} ) { - $request_url->path('api/v1/trip'); + $request_url->path('api/v2/trip'); $request_url->query_form( tripId => $trip_id, ); diff --git a/lib/Travel/Status/MOTIS/Polyline.pm b/lib/Travel/Status/MOTIS/Polyline.pm index ea46526..4bf5cde 100644 --- a/lib/Travel/Status/MOTIS/Polyline.pm +++ b/lib/Travel/Status/MOTIS/Polyline.pm @@ -23,7 +23,10 @@ our $VERSION = '0.01'; # <http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/> # to perl sub decode_polyline { - my ($encoded) = @_; + my ( $input ) = @_; + + my $encoded = $input->{points}; + my $precision = $input->{precision}; my $length = length $encoded; my $index = 0; @@ -80,14 +83,14 @@ sub decode_polyline { } # The actual latitude and longitude values were multiplied by - # 1e5 before encoding so that they could be converted to a 32-bit - # integer representation. (With a decimal accuracy of 7 places) + # 1e$precision before encoding so that they could be converted to a 32-bit + # integer representation. (With a decimal accuracy of $precision places) # Convert back to original values. push( @points, { - lat => $lat * 1e-7, - lon => $lon * 1e-7 + lat => $lat * (10 ** -$precision), + lon => $lon * (10 ** -$precision), } ); } diff --git a/lib/Travel/Status/MOTIS/Trip.pm b/lib/Travel/Status/MOTIS/Trip.pm index f9e14b4..42e75b8 100644 --- a/lib/Travel/Status/MOTIS/Trip.pm +++ b/lib/Travel/Status/MOTIS/Trip.pm @@ -53,7 +53,7 @@ sub new { raw_stopovers => [ $json->{from}, @{ $json->{intermediateStops} }, $json->{to} ], - raw_polyline => $json->{legGeometry}->{points}, + raw_polyline => $json->{legGeometry}, }; $ref->{scheduled_departure} = DateTime::Format::ISO8601->parse_datetime( |
