Implement locate() functions.

There's some ugly copy-pasting going on here, hope I can solve that a
little more elegantly later. But for the moment I won't dig too deep
into that.