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 that will also generate more than a million dollars for enforcement and regulation of the ride-hailing industry itself. In South Carolina, a 1 percent ride-hailing fee has yielded more than a million dollars for municipalities and counties to spend as they choose.

And 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 a rival — the struggling taxi industry — adapt with new technologies and job training.

As ride-hailing services become a dominant force across the country, they have increased congestion, threatened taxi industries and posed political and legal challenges for cities and states struggling to regulate the high-tech 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 in revenue to pay not only for transportation and infrastructure needs, but also a host of programs and services that have nothing to do with the ride-hailing apps.