In Chicago, a 15-cent fee on Uber, Lyft and other ride-hailing services is helping to pay for track, signal and electrical upgrades to make the city’s trains run faster and smoother.

Ride-hailing trips in Philadelphia are expected to raise $2.6 million this year for the city’s public schools through a 1.4 percent tax to generate more than $1 million for enforcement and regulation of the ride-hailing industry itself. In South Carolina, a 1 percent ride-hailing fee has yielded more than $1 million for municipalities and counties to spend as they choose.

Massachusetts began collecting 20 cents for every ride-hailing trip this month, earmarking the revenue to improve roads and bridges, fill a state transportation fund and even help the struggling taxi industry adapt with new technologies and job training.

As ride-hailing becomes a dominant force across the country, the services have increased congestion, threatened taxi industries and posed political and legal challenges for cities and states struggling to regulate the newcomers. But they are also proving to be an unexpected boon for municipalities that are increasingly latching onto their success — and being rewarded with millions to pay not only for transportation and infrastructure needs, but also a host of programs and services that have nothing to do with ride-hailing.

Now New York is seeking to join this growing wave with a new surcharge on ride-hailing and taxi trips that could become a central piece of an ambitious congestion pricing plan for Manhattan. A state task force has proposed fees of $2 to $5 per ride that would be among the highest in the nation — and could generate up to $605 million a year for the city’s failing subway system.

“We used to have yellow cabs, we now have yellow cabs and black cars and green cars and every color in the rainbow and they cruise downtown Manhattan to pick up fares,” Gov. Andrew Cuomo has said. “That is one of the first places I would look to reduce congestion and to raise money.”

Even as President Donald Trump promotes a plan to rebuild the country’s tattered infrastructure, many local governments are not waiting to see what, if any, help Washington provides and are finding novel ways to pay for transportation and other ­public works projects.

Across the nation, more than a dozen states and municipalities have imposed fees or taxes on ride-hailing companies or their passengers, or sometimes both, and many more are considering such measures, according to transportation and tax experts. Advocates for the charges contend the ride-hailing cars should pay for using public streets and resources, contributing to gridlock and pollution, and siphoning passengers and fares from public transit.

“If they want to share the pie, then they have to pay the price,” said Fayez Khozindar, executive director of the United Taxidrivers Community Council, an advocacy group for taxi drivers in ­Chicago. “It’s fair because we know the city is short on funds and they want to fill the hole.”

But some drivers and passengers for the ride-hailing companies say they have been unfairly singled out — in many places the new fees do not apply to taxis.

“Uber and Lyft have always been an easy target for cities looking for new streams of revenue,” said Harry Campbell, a driver for Uber and Lyft in ­California who writes a popular blog, the Rideshare Guy.

In New York and Chicago, Uber and Lyft have said they see their services as complementing the public transit systems and providing another option for riders, especially in transit deserts with few bus routes and train lines. Uber supports a congestion plan for Manhattan — even ­running an ad campaign backing the idea — as long as it does not single out for-hire vehicles.

“A comprehensive congestion pricing plan that is applied to all vehicles in the central business district is the best way to fully fund mass transit, reduce congestion and improve transportation for outer borough New Yorkers,” said Uber spokeswoman, Alix Anfang. “A surcharge alone will not accomplish these goals.”

Last year, New York state approved a 4 percent assessment on ride-hailing trips that begin outside New York City (rides in the city are already subject to state and local taxes). It is expected to raise $24 million a year for the state’s general fund, though one state legislator, Sen. John Brooks, D-Long Island, has proposed legislation to direct that revenue to local bus and commuter rail services.

South Carolina added a 1 percent fee to ride-hailing trips in 2015, in part to establish a single regulatory framework and block local efforts to charge prohibitively high fees to keep them out, state officials said. Now that fee has become a source of extra cash. The city of North Charleston, for instance, receives more than $30,000 annually and uses it for municipal operations.

Chicago officials have calculated that ride-hailing companies have cost the city about $40 million a year in lost revenue from transit fares, parking fees, licenses and permits. In 2014, the city imposed a 20-cent fee on ride-hailing trips in response to concerns that taxis were being undercut. Two years later, that fee went up to 50 cents, with an additional 2-cent fee paid by the ride-hailing companies themselves. And now, the new 15-cent fee for the transit system brings the total to 65 cents for passengers.

The city also assessed a separate $5 fee on passengers who were picked up or dropped off by ride-hailing cars at the major airports, the convention center and the Navy Pier.

The ride-hailing fees produced nearly $39 million for the city’s general fund in 2016, up from about $100,000 in 2014. Last year’s revenue, which is still being collected, is expected to reach $72 million.

Chicago Mayor Rahm Emanuel, who has made modernizing the “L” a priority, said the new 15-cent fee was the first of its kind to raise money solely for public transit from those who might not even use it because they could afford the ride-hailing cars. “I think it’s a progressive transportation tax. It will make public transportation competitive with the ride-share industry.”