How to compute distances from GPS history

I came here a while ago looking for a solution. I implemented something from that pseudocode. I didn’t think it would work well, but after a lot of tweaking, I came up with something that’s acceptable for what I needed it for: Movement Integration -- Distance and mode of transit tracking.