The relationship worked: Rail travelers needed somewhere to sleep, so railroad companies got into the lodging business.
Though the earliest railroad hotels in the United States were primarily for railway workers, later hotels catered to the lavish lifestyles of Gilded Age travelers.
"The people who are taking long-distance railroad excursions in the 1880s, 1890s, are generally quite well-to-do people," said Andrew Sandoval-Strausz, a professor at the University of New Mexico and author of "Hotel: An American History."
Many of the country's grand railroad hotels were constructed from the 1880s through the first decade of the 20th century.
It was a fine time to be rich (before U.S. income tax) and a fine time to operate a luxury hotel (before cars changed travel patterns forever).
The new hotels often also offered some less-expensive rooms to attract the rising middle class, Sandoval-Strausz said.
Though Canada has a slightly different railway-hotel history, lavish château-inspired hotels built by railroad companies started popping up there during the same period.
Fortunately for travelers today, some of the railroad hotels across the U.S. and Canada are still taking reservations:
1. Grand Hotel, Mackinac Island, Michigan
To meet a rising demand for suitable summer lodging on Michigan's scenic Mackinac Island, the Michigan Central Railroad, the Grand Rapids and Indiana Railroad, and the Detroit and Cleveland Steamship Navigation Company partnered in 1886 to form the Mackinac Island Hotel Co.
The wood-frame Grand Hotel opened the following year to guests who arrived by steamer and rail to sit and socialize on the hotel's impressive 660-foot-long front porch. Rates were $3 to $5 a night.
By the end of the 19th century, cars had arrived on the island but were quickly banned by a law that was finally strictly enforced in the 1930s. The island is still car-free today.
Rates at the Grand Hotel, which opens for the season May 6, start at $304 per person, per night.
, 286 Grand Ave., Mackinac Island, Michigan
2. Fairmont Banff Springs, Banff, Alberta
After the Canadian Pacific Railway was completed in 1885
, general manager William Cornelius Van Horne wanted to boost ridership and realize the tourism potential of the Canadian West.
The luxurious Banff Springs Hotel in Alberta, now a Fairmont property, was among the first hotels built by the railway to realize Van Horne's vision.
Designed by New York architect Bruce Price to resemble the castles of Scotland, the hotel opened in 1888.
The hotel standing today was built in the late 1920s after fire destroyed the original building in 1926.
It's within Banff National Park, and railway enthusiasts can still arrive by train through excursions organized by tour company Rocky Mountaineer
Starting Banff Springs room rates range from about U.S. $300 to $450 this spring, depending on room type and occupancy.
Fairmont Banff Springs
, 405 Spray Ave., Banff, Alberta
3. Fairmont Le Château Frontenac, Québec City
Architect Bruce Price also designed Le Château Frontenac in Québec City, another grand Canadian Pacific Railway project.
The hotel, which sits imposingly above the St. Lawrence River, opened in 1893.
A National Historic Site of Canada
, it was the first in a series of elegant château-style hotels built by the railroad.
Today, the Fairmont property boasts an indoor pool and spa, ski shuttles to slopes outside the city, afternoon tea and several restaurant options.
Québec City's train station is about five minutes away.
Spring 2016 rates start around U.S. $150 a night.
Fairmont Le Château Frontenac
, 1 rue des Carrières, Québec City
4. The Breakers, Palm Beach, Florida
In the 1890s, magnate Henry Morrison Flagler extended the Florida East Coast Railroad to what is now West Palm Beach.
"There's a perfect example for you of a railway that's leading the settlement of a region," Sandoval-Strausz said. "South Florida is very lightly inhabited before Henry Flagler runs a railway down there."
After establishing the grand Royal Poinciana hotel in 1894 on Lake Worth, Flagler opened the oceanfront Palm Beach Inn in 1896.
Renamed The Breakers in 1901 because of its proximity to the breaking waves, the hotel is in its third incarnation after fire destroyed the original wood-frame building in 1903 and another fire blazed through the hotel in 1925.
Today's hotel, which opened in 1926, is a lavish Italian Renaissance-style resort.
The rail station and the trestle that serviced it were destroyed in the 1930s, so cars are the norm for arriving guests.
May room rates start at $449, with summer promotional rates starting at $369.
, One South Country Road, Palm Beach, Florida
5. El Tovar, Grand Canyon, Arizona
Railroads were involved in the construction of a number of hotels in the American West's national parks.
The Great Northern Railway
and its hotel subsidiary built numerous hotels and chalets in Montana's Glacier National Park.
At the Grand Canyon in Arizona, the Swiss-chalet and Norwegian-villa-inspired El Tovar opened its doors in 1905.
The lodge, perched on the Grand Canyon's rim, was designed by Chicago architect Charles Whittlesey, the chief architect for the Atchison, Topeka and Santa Fe Railway.
The influential Fred Harvey Co
. operated the hotel in conjunction with the railway. Harvey, who died in 1901, started out in 1876 with restaurants catering to rail travelers on tight schedules and soon expanded into hotels and gift shops.
Trains still run to El Tovar on the same line as the Atchison, Topeka and Santa Fe Railway, every day except Christmas.
Rates this year start at $207.
1 El Tovar Road, Grand Canyon Village, Arizona
6. The Greenbrier, White Sulphur Springs, West Virginia
Guests were "taking the waters" in White Sulphur Springs, West Virginia, more than a century before the railroad bought the resort and revived it for 20th-century visitors.
In 1869, the first passengers stepped off the train practically on the resort's doorstep, but it wasn't until 1910 that the Chesapeake and Ohio Railway purchased the property with big plans for expansion.
The railroad-built Greenbrier Hotel opened in 1913, complete with a new spa and golf course.
Though rail traffic has long since declined in favor of cars and airplanes, the Greenbrier is still accessible by train.
"I'm always encouraging people by telling them that the historically correct way to come to the Greenbrier is to take the train," said Bob Conte, the resort's historian of nearly four decades.
Spring rates vary depending on dates and hotel events. There's a three-night promotion for the price of two available for much of April and May.
, 300 W. Main St., White Sulphur Springs, West Virginia
7. InterContinental New York Barclay, New York
With the construction of the Grand Central Terminal in New York between 1903 and 1913, the New York Central Railroad electrified its tracks and put them underground, creating valuable real estate above the rails.
The Barclay, which opened in 1926, was built on "air rights" leased from the New York Central Realty and Terminal Corporation, a division of the Vanderbilt-owned railroad.
It was the last of four railroad hotels built around the terminal. Tracks to Grand Central are still located under the hotel, although underground passageways to the station are no longer in use.
Today, the InterContinental New York Barclay is on the verge of reopening after an $180 million renovation of the original hotel designed by Cross & Cross, the architectural firm behind Fifth Avenue's Tiffany & Co. building.
Slated to open at the end of April, rates start at $379 for rooms and $1,100 for suites.