It's maritime custom to fly the flag of a nation when in their waters. I believe it is from the foremast on sailing ships. There's a beautiful illustration of RMS Titanic in which the Stars and Stripes are flying from its foremast. In the early '70's, I was a sea scout. When we "dieseled" up the Hudson River and into Canadian waters, we flew the Canadian National Ensign from the starboard spreader of our (only) mast. The U.S. National Ensign was flown from the required position, the stern flagstaff.