Is facing the Qiblah necessary in prayer?
There is no difference of opinion among the scholars concerning the fact that facing the Qiblah is one of the conditions of prayer being valid , and that failing to meet this condition – when one is able to do so – renders the prayer invalid. But there are some cases in which the requirement to face the Qiblah is waived .
If the Muslim is in a place where he cannot determine the direction of the Qiblah, then he should pray facing the direction which he thinks is most likely to be the direction of the Qiblah, and he does not have to repeat the prayer after that. Rather his prayer is valid but he does not have to do anything else.
This is indicated by the Hadith of Jabir (may Allah be pleased with him) who said:
We were with the Messenger of Allah (blessings and peace of Allah be upon him) on a march or a campaign, and it became cloudy. We tried to determine the Qiblah and differed concerning it, so each man prayed on his own, and one of us marked the direction he faced him so that he could check it later. The following morning we looked and found that we had prayed facing a direction other than the Qiblah. We told the Prophet (blessings and peace of Allah be upon him) and he did not instruct us to repeat it, and he said: “Your prayer is valid.” (Narrated by Ad-Daraqutni, Al-Hakim and Al-Bayhaqi; classed as sound by Al-Albani because of corroborating reports in Irwa’ Al-Ghalil, 291.)
Shaykh Ibn Baz (may Allah have mercy on him) was asked about the ruling on one who prays facing a direction other than the Qiblah after trying to work it out.
He replied:
“If the Muslim is on a journey or is in a land where it is not easy for him to find someone who can show him the direction of the Qiblah, then his prayer is valid, if he did his best to work out the direction of the Qiblah , then realised that he prayed facing the wrong direction.
But if he is in a Muslim country, then his prayer is not valid, because he could have asked someone to show him the direction of the Qiblah, or he could have worked out the Qiblah by looking at the mosques.” (Majmu` Al-Fatawa, 10/420)
How to find Qiblah direction
There are many ways of finding out the direction of the Qiblah . If the Muslim is travelling and he knows that he will be in a place where he would not be able to work out the direction of the Qiblah and there are no Muslims there whom he can ask, then he should make sure to learn some of the ways in which he can determine the direction of the Qiblah . That is very easy nowadays, by means of compasses or some watches that contain a program that shows the direction of the Qiblah, either by means of the sun or the moon.
So the Muslim should learn that which will make his prayer valid.
And Allah knows best.