Nearest, next are both superlative forms of near, but they are not always interchangeable.
Nearest may be used wherever the intent is merely to indicate the highest degree of propinquity (as in space, time, or kinship).
Next has lost this sense and usually implies immediate succession, or sometimes precedence, in an order, a series, or a sequence; thus, the next house is the house just beyond the one in mind in a row or series of houses; their next child is the one who comes after the child under consideration in order of birth; the next best is the second best in a rating or choice.
But in law one’s nearest relative is one’s “next of kin”; one’s “next friend” is a person (as a near relative or natural guardian) who has the right or is appointed by a court to act for a person (as an infant) who by the law of the state has not full legal capacity to sue or make other legal moves. In ordinary language “nearest of kin” is found as often as “next of kin,” but “nearest friend” applies distinctively to one’s most intimate friend.