We do this for NJ Transit with about 90% accuracy. We spent at least two months figuring out how it all works, though. It's non-trivial to do right.