Wireless capsule endoscopes (WCEs) are pill-sized camera-embedded devices that can provide visualization of the gastrointestinal (GI) tract by capturing and transmitting images to an external receiver. Determination of the exact location of the WCE is crucial for the accurate navigation of the WCE through external guidance, tracking of the GI abnormality, and the treatment of the detected disease. Despite the enormous progress in the real-time tracking of the WCE, a well-calibrated analytical model is still missing for the accurate localization of WCEs by the measurements from different onboard sensing units. In this paper, a well-calibrated analytical model for the magnetic localization of the WCE was established by optimizing the magnetic moment in the magnetic dipole model. The Jacobian-based iterative method was employed to solve the position of the WCE. An error model was established and experimentally verified for the analysis and prediction of the localization errors caused by inaccurate measurements from the magnetic field sensor. The assessment of the real-time localization of the WCE was performed via experimental trials using an external permanent magnet (EPM) mounted on a robotic manipulator and a WCE equipped with a 3-axis magnetic field sensor and an inertial measurement unit (IMU). The localization errors were measured under different translational and rotational motion modes and working spaces. The results showed that the selection of workspace (distance relative to the EPM) could lead to different positioning errors. The proposed magnetic localization method holds great potential for the real-time localization of WCEs when performing complex motions during GI diagnosis.