كُنَّا مَعَ رَسُولِ اللَّهِ ـ صلى الله عليه وسلم ـ فِي سَفَرٍ فَتَغَيَّمَتِ السَّمَاءُ وَأَشْكَلَتْ عَلَيْنَا الْقِبْلَةُ فَصَلَّيْنَا وَأَعْلَمْنَا فَلَمَّا طَلَعَتِ الشَّمْسُ إِذَا نَحْنُ قَدْ صَلَّيْنَا لِغَيْرِ الْقِبْلَةِ فَذَكَرْنَا ذَلِكَ لِلنَّبِيِّ ـ صلى الله عليه وسلم ـ فَأَنْزَلَ اللَّهُ {فَأَيْنَمَا تُوَلُّوا فَثَمَّ وَجْهُ اللَّهِ} .
It was narrated from ‘Abdullah bin ‘Amir bin Rabi’ah that his father said:
“We were with the Messenger of Allah (ﷺ) on a journey, and the sky was overcast so it was difficult for us to determine the Qiblah. So we performed prayer, and we marked the location.* Later, when the sun reappeared, we realized that we had prayed facing a direction other than the Qiblah. We mentioned that to the Prophet (ﷺ), then the Words were revealed: ‘So wherever you turn there is the Face of Allah.’” [2:115]
‘Āmir ibn Rabī‘ah (may Allah be pleased with him) reported: We were with the Prophet (may Allah's peace and blessings be upon him) on a journey on a very dark night and we didn't know the direction of the Qiblah. So each man among us prayed in his own direction. In the morning, when we mentioned…
فَصَلَّى كُلُّ رَجُلٍ مِنَّا عَلَى حِيَالِهِ فَلَمَّا أَصْبَحْنَا ذَكَرْنَا ذَلِكَ لِلنَّبِيِّ صلى الله عليه وسلم فَنَزَلَ: (فَأَيْنَمَا تُولُّوا فَثَمَّ وَجْهُ الله)