refactor code to save marker position to the db