How to calculate passed (driven) distance -real time- with android and without Google MAP API

I am trying to develop an android app for drivers. I want drivers would be able to check how many kilometers or meters passed (in real-time fashion). I know google map has API for that, but I want to use a free/ opensource API for my application. I prefer the most accurate algorithm or APIs.

I have tried google map API, HERE, TOMTOM and MapBox APIs.