It is Sunnah for the one who is traveling by sea or by land to shorten the four-rak‘ah prayers to two rak‘ahs whilst travelling. It is also Sunnah for him to put prayers together when he needs to. For more information, please see the answer to question no. 98574 and 111916.
With regard to determining the direction of the qiblah, that is not difficult nowadays, with the availability of modern devices that will determine the direction, such as compasses and the like.
He must pray facing towards the qiblah in obligatory prayers, and he should turn as the ship turns to the best of his ability. This has to do with the obligatory prayers.
In the case of the naafil (supererogatory) prayers, he should turn to face the qiblah at the beginning of the prayer, then after that it does not matter if the ship turns away from the qiblah. It says in Fataawa al-Lajnah ad-Daa’imah (8/121):
Q: If the traveler wants to offer his prayer on board the airplane or ship, or he could not find water and did not do tayammum, and the time for prayer has come, and he does not know the qiblah, is it permissible for him to pray? How should he prayed, and which direction should he face?
Answer: If the time for prayer comes on the airplane or ship, the Muslim who is on board must offer the prayer that is currently due, according to his circumstances and ability. If water is available, he must purify himself with it. If he cannot find water, or if water is available but he is unable to use it, he must do tayammum, if he can find dust or the like. If he can find neither water nor dust, nor any alternative to dust, then that requirement is waived in his case and he should pray according to his situation, because Allah, may He be exalted, says (interpretation of the meaning): “So keep your duty to Allah and fear Him as much as you can” [al-Taghaabun 64:16] . He also has to face towards the qiblah, and turn with the airplane when it turns to the best of his ability, in the obligatory prayer. However, in a naafil (supererogatory) prayer he may pray facing the direction in which the plane is traveling, because when traveling, the Prophet (blessings and peace of Allah be upon him) would offer naafil prayers atop his mount in whatever direction he was facing. It is proven in the hadeeth of Anas that it is prescribed to face towards the qiblah when starting the prayer in the case of a naafil prayer whilst travelling.
But in the event that a person is unable to find out the direction of the qiblah and face towards it, and also fears that the time for the obligatory prayer will end, then he should try his best to determine the direction of the qiblah and pray facing that direction, and he does not have to repeat the prayer if it later becomes clear to him that he was wrong about the direction of the qiblah.