WASHINGTON—Police must get a search warrant before obtaining data showing the location of cellphone users, the Supreme Court ruled Friday, the third in a string of decisions that limit law enforcement’s access to the most intimate details of citizens’ digital lives.

“When the government tracks the location of a cell phone it achieves near perfect surveillance, as if it had attached an ankle monitor to the phone’s user,” Chief Justice John Roberts wrote in the 5-4 opinion.

“Unlike...