And from where so ever you start forth (for prayers), turn your face in the direction of Al-Masjid-Al-Harâm (at Makkah), and where so ever you are, turn your faces towards, it (when you pray) so that men may have no argument against you except those of them that are wrong-doers, (2:150)(Holy Quran)
The obligation to face the direction of the Ka'bah is removed from a warrior having to pray the Fear Prayer and during severe fighting. It is also removed from one who is rendered incapable of it, such as one who is (very) ill, or one who is upon a ship, car or airplane and who fears that the Prayer time will reach its end. It is also removed from one who prays optional Prayer or the Witr Prayer upon a riding beast or vehicle. It is, however, preferable for him, if he is able, to turn it towards the Qiblah for the initial takbeer. After that it does not matter in which direction it turns.
THE RULING CONCERNING PRAYING TOWARDS A DIRECTION OTHER THAN THAT OF THE KA'BAH BY MISTAKE
If a person prays towards other than the Qiblah due to the sky being cloudy or for any reason other than that, after having tried to the best of his knowledge and ability to face the correct direction, then his Prayer will be correct and he will not have to repeat it.
However if a person whom he holds to be reliable comes to him whilst he is praying and informs him of the correct direction, then he must immediately turn to the correct direction, and his Prayer will be correct.