tesseract and the bus system
being new to the bus system at cornell/ithaca had me thinking about a quick app (iOS or web) that could tell me what bus to take (from a nearby stop) to get to where i wanted to go. i’m sure this problem has been solved before, and i’m sure pretty thoroughly. i like re-inventing the wheel – it helps me learn.
i’m going to need…
a couple of things:
- the gps location of the user/phone
- the latlong locations of all the bus stops
- the bus routes (what stops they go to – in order – and the time)
it would give me a quick introduction to
- gps location on web apps
- neo4j (i figure bus routes are a graph…)
mini-hacks
i hate using the term ‘hack’, in pretty much all contexts. hacking the gibson, can’t hack it, hack-a-thon, computer hacker, hacky sack. despite this, i realized i need to focus on smaller, more achievable goals for my hobbies, especially since my time will be limited once i start working. so i’m trying to start something i’m begrudgingly calling ‘mini-hacks’. this will be my first.
tesseract
i have the name. now i need a clear and simple goal – find the nearest bus stop by loading up a web page. we can build from there.
scraping a site
i went to the tcat bus system website and went to their google maps powered page. after some failed chrome exploring (you can’t copy a large amount of data out of the response body), i ended up at my go-to browser Firefox (complete with firebug). i grabbed all the stops and dumped them to individual .js files. with some quick console exploring (chrome dev tools shine at this), i found the array and element structure and put the snippet below together. i now have a CSV with stop names and lat/long locations. finding which one is closer should be something quick… :)
and the code
var s = 'cornell';
function printStop(element) {
document.write(element.name + ',');
document.write(element.latlng.lat + ',');
document.write(element.latlng.lng + ',');
document.write(s + 'br');
}
s = 'cornell';
cornell.kmlOverlay.markers.forEach(printStop);
s = 'county';
county.kmlOverlay.markers.forEach(printStop);
s = 'downtown';
downtown.kmlOverlay.markers.forEach(printStop);i created high level objects (cornell, county, downtown) from each of the response bodies.
at the very least, i hope this post shows me what i was doing one day, struggling with a new bus system…

