Praise be to Allah.
Facing the qiblah is one of the conditions of prayer being valid. Every worshipper has to make sure he faces the qiblah in his prayer, and strive to make sure he is facing in the right direction, whether by means of natural signs or using a compass, if he is able to do that, or by asking trustworthy people in that place who know in which direction the qiblah is.
It seems most likely in the case that you describe that the deviation from the qiblah was very slight. This slight deviation is something that can happen when a person who lives in that area is a little confused and people do not pay attention to this slight difference in direction. If that is the case, i.e., if the deviation from the qiblah was slight, then it does not matter and it does not invalidate the prayer, because those who are far away from the Ka’bah have to face in its general direction; they do not have to face precisely in that direction, because al-Tirmidhi (342) and Ibn Maajah (1011) narrated that Abu Hurayrah (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings of Allah be upon him) said: “Whatever is between the east and the west is the qiblah.” Classed as saheeh by al-Albani in al-Irwa’.
Al-San’aani (may Allah have mercy on him) said in Subul al-Salam (1/260). This hadith indicates that what is required is to face in that direction, and not towards the precise location of the Ka’bah when one cannot see it.
Further evidence to this effect is to be seen in the report narrated by al-Bukhari (144) and Muslim (264) from Abu Ayyoob (may Allah be pleased with him) who said that the Prophet (peace and blessings of Allah be upon him) said: “If you need to relieve yourself, then do not face the qiblah or turn your back towards it, whether you are urinating or defecating, rather face to the east or to the west.”
Shaykh al-Islam (may Allah have mercy on him) said in Sharh al-‘Umdah: This is stating that facing any direction other than the east or the west means that one is either facing the qiblah or turning one’s back towards it. This was addressed to the people of Madeenah and everyone who was in the same direction (in relation to Makkah), because this was the consensus of the Sahaabah (may Allah be pleased with them). ‘Umar said: Whatever is between the east and the west is the qiblah except at the House. And it was narrated that ‘Uthmaan (may Allah be pleased with him) said: How can a man make a mistake in his prayer when whatever is between the east and the west is the qiblah, so long he does not turn towards the east deliberately.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: Thus we know that the matter is broad in scope. So if we see a person praying in a direction that is slightly off from the qiblah, that does not matter, because he is facing in its general direction, and this is what he is obliged to do.
Al-Sharh al-Mumti’, 2/273
But if the deviation from the direction of the qiblah was very great, so that you were not praying in the direction of the qiblah at all, such as if you were praying towards the east when the qiblah is towards the west or the north, for example, so long as you based your action on the words of someone who you know attaches great importance to the prayer and you thought that they knew better about the direction of the qiblah, then you do not have to do anything, and the prayers which you offered are still valid, even if you faced the wrong direction when you prayed, because if a person tries his best to get it right, he has done what is required of him, as Allah says (interpretation of the meaning):
“So keep your duty to Allah and fear Him as much as you can” [Al-Taghaabun 64:16]
It says in Fataawa al-Lajnah al-Daa’imah (6/314): If a worshipper does his best to figure out the direction of the qiblah and prays, then he finds out that he was mistaken, his prayer is still valid.
In Fataawa al-Shaykh Ibn Baaz (may Allah have mercy on him) (10/421) it says: If a believer does his best to figure out the direction of the qiblah, when he is in the desert or is in a city in which he is not sure where the qiblah is, and he prays on that basis, then he finds out that he prayed in a direction other than the qiblah, then he should continue to pray according to his latest estimate, if he believes that it is more correct than his first estimate. His first prayer is still valid because he did his best to work out the qiblah.