In recent years, smartphone sensors have become one of the most important and easily available sensors to facilitate people's lives, especially in health care and positioning (indoor environments). However, the data coming from smartphone sensors can be distorted during the user’s movement such as irrelevant movements, walk mode, and speed of walking. This distortion (noise) impairs the estimated distance accuracy (accumulative error) which increases with increasing walking distance. In addition, the accuracy of the distance traveled is affected by the user's speed, as the speed affects the step length. This work proposes a novel approach for calculating step length in an indoor environment using data from a smartphone sensor. The contribution of this work is to determine the dynamic step length and to increase the accuracy of the distance traveled measurement, through the use of a step frequency that can provide the user's speed, and through the determination of the step error criterion that will be used in adjusting the distance traveled. The experimental results show that the proposed method achieves 99.11 percent accuracy over existing approaches when a pedestrian is walking in multiple mode changes.