I belive a trai is used more in the sense of to live/to exist whereas a locui is more in the sense of to be located. I'm not a native speaker though so not entirely sure
I asked some native speaker friends of mine to explain me the difference. "A trăi", as you said, is used whenever you mean that you exist, that you are alive, when you mean the opposite of "being dead". "A locui" instead is used to mean that you reside in / inhabit a place (a building, a city)