get distance logic