By having a base map of the gravity of the ocean floor. Picture a contour map, but for values of g.
Same as if you were navigating based on a physical contour map of the ocean floor, except that getting an accurate depth like that in deep waters isn’t possible, and in shallow waters requires sonar.