Home-sharing services like Airbnb are creating an awkward dilemma for cities and counties, especially in areas where housing costs are high. Municipalities are struggling to balance the economic boost from the growth of home-sharing services with the pressing need for affordable housing.

Before we go any further, let’s put the considerable growth of such services into perspective. One study found that 400,000 Airbnb guests who visited New York City in 2012 and 2013 spent $632 million, supporting 4,580 jobs. As compared to tourists staying in hotels, Airbnb guests tended to stay two days longer and spent nearly $200 more at local businesses during their visit.

But in New York as in other cities and counties, this new revenue comes with a hitch: Home-sharing services take apartments off the long-term rental market and are a factor in driving up rents to unaffordable levels. Airbnb alone has 1.5 million listings in 34,000 cities.

The problem is particularly acute in New York City, despite a state law that prohibits residential properties with three or more units from being rented for less than 30 days unless the permanent resident is present. According to a report released in June by a consortium of housing activists, 55 percent of the 51,000 Airbnb listings in New York City violate that law. (This June the New York Legislature passed a law barring the listing of such units on a home-sharing site; violators could be fined up to $7,500.)

The report contends that the number of vacant and available apartments in New York City would increase by 10 percent if “commercial profiteer” listings -- listings that are booked several times per month and listed for at least three months per year by someone who advertises multiple apartments on Airbnb -- were returned to the rental market. Presumably, rents would drop by an offsetting amount, making for significantly more affordable shelter for low- and moderate-income families.

The study showed that rents had risen fastest in the New York City neighborhoods where Airbnb is the most popular -- including gentrifying, predominantly minority neighborhoods like Bedford-Stuyvesant. It’s only fair to note that the report was commissioned by affordable housing advocates who have long been critics of Airbnb.

New York is not alone in trying to deal with its home-sharing dilemma. Municipal leaders around the globe are increasingly torn between how to balance the goals of affordable housing and still reap the vitality and revenue from the so-called sharing economy.

In Chicago, city aldermen passed an ordinance in June, backed by Mayor Rahm Emanuel, that imposes a 4 percent surcharge on short-term rentals -- that is, in addition to Chicago’s 17.4 percent hotel tax. The surtax will be used to help fund services for the homeless.

San Francisco, where rents are infamously high, requires short-term rental sites to take down any rental listing not registered with the city or be subject to fines for each one. Airbnb is attempting to block the ordinance by suing the city in federal court. It claims the city is violating the Communications Decency Act, which prevents governments from holding Internet platforms liable for content created by their users.

Meanwhile, several cities are tapping into home-sharing as a revenue stream -- ignoring, for now, the issue of affordable housing. In a recent deal worth about $5 million a year to Los Angeles, Airbnb will collect lodging taxes from rental hosts who are supposed to, but often do not, pay the same kind of lodging taxes as hotels. L.A. tax officials have struggled to track down hosts and make sure they pay. Now they’ll get some help from Airbnb itself.

“There is going to be a lot of debate about how this industry is regulated,” Miguel Santana, L.A.’s top budget official, told the Los Angeles Times. “We just want to make sure that while that conversation is taking place, the city is not missing out on millions of dollars in revenues.”