Is it possible to have astral projection in minecraft?

I was thinking an idea that if players went into Spectator mode once they got out of it they teleported back to where they were so they cant travel anywhere, does anyone have any ideas on how to do it?