Save and retrieve the distance from the database