How to calculate total distance between origin and current location when vehicle is moving

Previously i am using ionic geolocation and google distance matrix api. But when the vehicle moving total distance calculation vale is increases suddenly.