God knew where he was, but he asked so as to start a conversation with Adam and avoid startling him too much to reply.
Commenting on Gen. 3:9; why should an omniscient God ask "Where are you?",

God knew where he was, but he asked so as to start a conversation with Adam and avoid startling him too much to reply.