Currently, pedestrian dead reckoning (PDR) is widely used in indoor positioning. Since there are restrictions on a device’s pose in the procedure of using a smartphone to perform the PDR algorithm, this study proposes a novel heading estimation solution by calculating the integral of acceleration along the direction of the user’s movement. First, a lightweight algorithm, that is, a finite state machine (FSM)-decision tree (DT), is used to monitor and recognize the device mode, and the characteristics of the gyroscope at the corners are used to improve the heading estimate performance during the linear phase. Moreover, to solve the problem of heading angle deviation accumulation on positioning, a map-aided particle filter (PF) and behavior perception techniques are introduced to constrain the heading and correct the trajectory through the wall after filtering. The results indicate that the recognition of phone pose can be 93.25%. The improved heading estimation method can achieve higher stability and accuracy than the traditional step-wise method. The localization error can reduce to approximately 2.2 m when the smartphone is held at certain orientations.