Service locator is a design pattern used to locate other services. It is the opposite of DI. Depending on its usage, it can be an antipattern when we move the dependency to the service locator instead of the concrete class.
The other issue with using service locator is that it can often be difficult to change the implementation and to test the system. Taking the opposite approach, IOC builds the dependencies once for each application when the application is launched for first time.
The goal of DI is to inject dependencies during the application initialization. If we call the dependencies later, this becomes a service location.