Although advancement has been observed in global navigation satellite systems and these systems are widely used, they cannot provide effective navigation and positioning services in covered areas and areas that lack strong signals, such as indoor environments. Therefore, in recent years, indoor positioning technology has become the focus of research and development. The magnetic field of the Earth is quite stable in an open environment. Due to differences in building and internal structures, this type of three-dimensional vector magnetic field is widely available indoors for indoor positioning. A smartphone magnetometer was used in this study to collect magnetic field data for constructing indoor magnetic field maps. Moreover, an acceleration sensor and a gyroscope were used to identify the position of a mobile phone and detect the number of steps travelled by users with the phone. This study designed a procedure for measuring the step length of users. All obtained information was input into a pedestrian dead reckoning (PDR) algorithm for calculating the position of the device. The indoor positioning accuracy of the PDR algorithm was optimised using magnetic gradients of magnetic field maps with a modified particle filter algorithm. Experimental results reveal that the indoor positioning accuracy was between 0.6 and 0.8 m for a testing area that was 85 m long and 33 m wide. This study effectively improved the indoor positioning accuracy and efficiency by using the particle filter method in combination with the PDR algorithm with the magnetic fingerprint map.