Autonomous underwater vehicles (AUV) are seen as an emerging technology for maritime exploration but are still restricted by the availability of short range, accurate positioning methods necessary, e.g., when docking remote assets. Typical techniques used for high-accuracy positioning in indoor use case scenarios, such as systems using ultra-wide band radio signals (UWB), cannot be applied for underwater positioning because of the quick absorption of the positioning medium caused by the water. Acoustic and optic solutions for underwater positioning also face known problems, such as the multi-path effects, high propagation delay (acoustics), and environmental dependency. This paper presents an oscillating magnetic field-based indoor and underwater positioning system. Unlike those radio wave-based positioning modalities, the magnetic approach generates a bubble-formed magnetic field that will not be deformed by the environmental variation because of the very similar permeability of water and air. The proposed system achieves an underwater positioning mean accuracy of 13.3 cm in 2D and 19.0 cm in 3D with the multi-lateration positioning method and concludes the potential of the magnetic field-based positioning technique for underwater applications. A similar accuracy was also achieved for various indoor environments that were used to test the influence of cluttered environment and of cross environment. The low cost and power consumption system is scalable for extensive coverage area and could plug-and-play without pre-calibration.