One of the coolest parts of PipesCamp on Sunday was the HackDay part of it. Okay, it wasn't a whole day, more like about three hours, but it was still fun. You can find my pipe here: MTC Mashup.
You can type a bus number in the input box on the top and it displays (or tries to display :P) the places visited by the bus on a map.
Check it out!
The raw data comes from the Chennai MTC website (Yes, they have a website). There is a section that gives the stages visited for the bus number that you enter in a form. However, the output is quite a messy bit of HTML, quite a pain to parse through. Luckily, Rabin Vincent has taken this data and put out a much cleaner bus query interface over it.
So, Rabin's site provides the raw data for the pipe. Given a bus number, we construct an appropriate URL and query Rabin's site for the bus route, then parse the HTML to extract out a list of stages that the bus goes through.
Now that we have the list of stages, the next step is to figure out the latitude and longitude of these places. For that, we used Yahoo's Geocode service. This service takes a string address and returns the latitude and longitude of the place. Once we have the lat/long coordinates of each of the stages, we send it out on a yahoo map.
Now for the hiccups:
The biggest by far is ambiguity while searching. For example, the MTC site refers to the Central Station stop simply as "Central" which when passed to the Geocoding API gets confused because a lot of things match this. At the other extreme, a bus stop like "P. Orr & Sons" does not get any hits on the Geocoding API. So, sometimes the lat/long positions can be all over the map depending on whether the Geocoding API returned the right place or not.
An obvious solution is to create a small web service that takes the names as specified on the MTC site and return the correct lat/long for that stop. So we know that Central refers to central station, and we can return the position of that stop accurately.
The other thing that I could not figure out was how to get the data on other maps. By default Y! Pipes uses Y! Maps (Worldwide) which does not have good resolution for Indian cities. However, there is a India specific Y! Maps, which has good detail for Indian cities. How do I get Pipes to output to the Y! India maps instead of the global Y! Maps? I couldn't figure that one out.
Right at the end, labsji took my mashup, downloaded the KML data and imported it into Google Earth, so that the whole route was superimposed on Google Earth and it automatically ran an animated tour between the stops.
In the end it was a fun experiment, and something I would not have done without PipesCamp. When I first started this hack, I though it would be impossible, but Y! Pipes allowed me to create the whole mashup in a few hours as a total newbie. That's pretty cool if you ask me.