Public IPs are leased and there is a directory of who holds those leases.
Who/where (address)specifically was using a given IP at a given time has to be answered by the organization who holds the leases and that usually requires a warrant.
Now, an individual can give up their location by having something running on their network and GPS... I.e. a phone... some apps report that info.... but with dhcp that data can get stale.
There is a lot more to it... but just getting general location I.e. city state... has been possible for 30+ years. There has never been anonymous on the internet unless you use certain techniques and those are not foolproof.