After suffering a spate of traffic jams (including one that caused my to go on a country lane rally drive) I vowed that I'd use technology to avoid this in future. You can always check websites before you travel and listen to radio bulletins but this is hit and miss, (i.e. remembering to check the website before you leave).
In the UK, the highways agency publish a bunch of XML feeds showing things like current roadworks, what's showing on the overhead matrix signs and planned roadworks. See here for the full list. I chose to use the "unplanned events" feed which uses their road sensor network to warn of incidents.
I've put the full code at the bottom of this posting but in simple terms it just:
1)Detects that I've unlocked the screen of my handset (which I'm doing all the time).
2)Checks that the time is either 6,7,8 in the morning or 4,5,6 in the evening (when I commute).
3)Does a HTTP GET to download the XML feed
4)Parses the feed to pick out a set of roads and place names I care about. This is controlled by the array:
var MyTrafficArray = ["Birmingham","Wolverhampton",">A34<",">M6<",">M5<"];
So you can just edit the terms in the array to change the set of roads. The "> <" for the road names means you get an exact match as this is how they're composed in the XML tags, e.g. avoid getting "M6" and "M60" mixed up.
Here's the tool in action. Firstly, after a screen unlock it warned me that there was a problem on one of the roads:
- Adding a timer rather than relying on a screen unlock.
- Mixing location/geo-fencing the XML feed to always be warned wherever I am.
- Playing with some of the other traffic feeds, (variable message signs looks fun).
- Using some of the other UK Government APIs (e.g. weather and crime).