Perl interface to Google Directions API

February 1st, 2012 robin Posted in google, Ironman, Perl, Travel No Comments »

Google has a pretty neat service for getting driving/cycling/walking directions between places, and now there’s a perl interface to it: Google::Directions (and on GitHub)

It’s Moosey and it’s juicy… I hope it helps you get from A to B with Perl a bit faster! 🙂

If anybody is top-fit with Moose::Util::TypeConstraints, I have some issues in this module which I don’t understand and would really appreciate some tips with. 🙂

And here’s some sample code:

#!/usr/bin/env perl
use strict;
use warnings;
use Google::Directions::Client;
use Getopt::Long;
my %params;
GetOptions( \%params,
 'origin=s',
 'destination=s',
 );
my $goog = Google::Directions::Client->new();
my $response = $goog->directions( %params );
my $first_leg = $response->routes->[0]->legs->[0];
printf( "That journey will take you %0.1f minutes and %0.1fkm\n",
 ( $first_leg->duration / 60 ),
 ( $first_leg->distance / 1000 ),
 );
# $> ./test_directions.pl --origin "Munich, Germany" --destination "Hamburg, Germany"
# That journey will take you 443.8 minutes and 778.5km

The effects of cycling 10000km

January 31st, 2012 robin Posted in Home, Travel 7 Comments »

This post should have come out in September 2011 because that’s when the odometer on my bike wrapped from 9999km to 0km.

The stats

  • New price: 450€ (city bike, aluminium frame, solid carrier, hub dynamo, …)
  • At the 10000km my bike was about 4 years old (but one year in storage)
  • I cycled an average of 3300km per year that I used it
  • Never cycled outside of Munich city
  • No recreational cycling – all commuting
  • Average speed with winter tyres: 15km/h
  • Average speed with summer tyres: 18km/h

How much wear and tear on the bike?

  • Replaced break blocks 3 times
  • Replaced 3 tyres
  • Replaced 2 tubes
  • Replaced break and gear cables
  • One broken crank shaft bearing
  • One new saddle
  • Replaced rear sprocket
  • Replaced crank set and pedals
  • Purchased studded winter tyres
  • Replaced front halogen lamp with powerful LED lamp
  • Lots of oil…
Total cost of maintenance over 3 years: ~250€

Total cost of ownership

Assuming a linear depreciation to 100€ over 5 years, the cost of the bicycle, plus maintenance (my work time not included): 127€/year

Given that at least 2/3 of the distance travelled was work related I can write off 5ct/km (flat-rate in German taxes): 110€ per year, so it only costs me ~17€ per year to cycle.

Had I driven that distance by car (assuming a car which I would own: a 7 year old compact) it would have cost me about 200€ taxes, 500€ insurance, 400€ maintenance, and 700€ depreciation, plus 188€ for petrol: 2000€, minus the tax deduction of 660€ leaves 1340€ for a small car.  Granted I wouldn’t have only driven the car in the city, so it’s not exactly comparable…

Had I got a year round ticked for the local municipal transport system (MVV), it would have cost me 438€ for public transport. This could be written off 100% by using the flat rate.

Other effects

  • Depending on the distance between home and work over the years, I had anything up to 1.5 hours of fresh air and light exercise per day.  At my last general medical check-up the doctor did a stress ECG on me and found all parameters well above “healthy”.  I’m sure that has something to do with cycling.
  • I haven’t had a single sick day in the last 10 years of work.  That’s not to say I was never sick, but nothing bad enough to keep me home.  Maybe not sitting in public transport (confined metal tubes full of coughing and sneezing people) helped too…
  • I hate sitting in traffic… I hardly ever sit in traffic… 🙂
  • Taking into account the time for walking to a car, driving through traffic, finding a parking spot, and walking from there to the destination, I’m always faster by bike than you will be by car in the city.
  • I’m always faster than public transport over short distances, and in the spring/summer/autumn faster over all distances (without breaking a sweat!).

Enough already?

Get on your bike! 🙂


Interface to EFA (Elektronische Fahrplan Auskunft)

January 23rd, 2012 robin Posted in Ironman, Perl, Travel No Comments »

I’m publishing this module now, even though it’s not complete because I foresee not getting round to developing it much in the near future, and maybe others can benefit from it in its current state, or continue development.

What is EFA?

EFA is a product from Mentz Datenverarbeitung in Munich which is used my many municipal travel providers such as the MVV in Munich to provide travel data for their patrons.

Unfortunately there is no documentation to the interface available, so my implementation is mostly reverse-engineered to their RESTful API.  A lot of ground work which helped me get ahead was done by Andreas and friends in Java with the public-transport-enabler (see AbstractEfaProvider in there for more details) which incidentally is the code behind the hugely popular android App Öffi.

What can I WWW::EFA for?

Querying travel times between locations, and stops within a municipal transport network.

Which municipalities will it work for?

There are loads of transport authorities which use EFA (London, Munich, Basel, San Francisco, …).  I have only tested it with the MVV…

Where are all the unit tests and examples?

Sorry… it’s a work in progress… I’d be really grateful for any contributions you want to make to make it more complete!!

What other similar perl modules are there?

Code example

use WWW::EFA::Provider::MVV;
use WWW::EFA::Coordinates;
use WWW::EFA::Location;
use Class::Date qw/now/;
my %efa_params;
my $efa = WWW::EFA::Provider::MVV->new( %efa_params );
my $search_to_location = WWW::EFA::Location->new(
 coordinates => WWW::EFA::Coordinates->new(  lat => 48.171606, lon => 11.498899 ),
 );
my $search_from_location = WWW::EFA::Location->new(
 coordinates => WWW::EFA::Coordinates->new( lat => 48.140267, lon => 11.557302 ),
 );
my( $from_location ) = $efa->coord_request(
 location => $search_from_location,
 max_results => 5,
 max_distance => 100,
 );
my( $to_location ) = $efa->coord_request(
 location => $search_to_location,
 max_results => 5,
 max_distance => 100,
 );
printf "##### Getting trips between\n%s\n%s\n",
 $from_location->string, $to_location->string;
my $trips = $efa->trips(
 from => $from_location,
 to => $to_location,
 date => now(),
 );
print $trips->string;