Learning Grid Cells And Remapping In Curved Space: A Gauge Theoretic Perspective