So the US knew the location of the Iranian ship off Sri Lanka bc both the US and Iran were part of a military exercise hosted by India which the US pulled out of at the last minute, presumably so as to bomb the unarmed Iranian ship.
The former Indian FM:

@AlisonCreekside It is very debatable which side of this conflict India will take. On one hand it's a key player of BRICS alongside Russia and China. On the other its the only country in the world that has consistently cheered on and fully supported the genocide against #palestine

Indian-Iranian relations are complex at best. But,
bombing India's unarmed invited guests probably doesn't do the Israel-US side any favours.