Alphabet’s Google GOOGL.O will pay $391.5 million to settle allegations by 40 states that the search and advertising giant illegally tracked users’ locations, the Michigan attorney general’s office said Monday.

The investigation and settlement, which was led by Oregon and Nebraska, is a sign of mounting legal headaches for the tech giant from state attorneys general who have aggressively targeted the firm’s user tracking practices in recent months.

In addition to the payment, Google must be more transparent with consumers about when location tracking is occurring and give users detailed information about location-tracking data on a special web page, the Iowa attorney general’s office said.

“When consumers make the decision to not share location data on their devices, they should be able to trust that a company will no longer track their every move,” Iowa Attorney General Tom Miller said in a statement. “This settlement makes it clear that companies must be transparent in how they track customers and abide by state and federal privacy laws.”

Google spokesperson Jose Castaneda said: “Consistent with improvements we’ve made in recent years, we have settled this investigation, which was based on outdated product policies that we changed years ago.”

Google said in a blog post on Monday that it would be “making updates in the coming months to provide even greater controls and transparency over location data.”

Those changes include making it easier to delete location data. New users will have auto-delete controls that allow them to order Google to delete certain information when it hits a certain age.

The state attorneys opened a probe in 2018 following a report that Google recorded location data even when users instruct it not to. The probe found that Google had misled consumers about location-tracking practices since at least 2014, in violation of state consumer protection laws.

Arizona filed a similar case against Google and settled it for $85 million in October 2022.

Texas, Indiana, Washington State and the District of Columbia sued Google in January over what they called deceptive location-tracking practices that invade users’ privacy.

Google had revenue of $111 billion from advertising in the first half of this year, more than any other seller of online ads. A consumer’s location is key to helping an advertiser cut through the digital clutter to make the ad more relevant and grab the consumer’s attention.