Make the location sensor work in the background

Hello, I’m working with the Google map and I need my app to receive the coordinates from firebase in real time, but that only works if the app is open, I want that to work in the background, besides that it also has emergent alerts and not they work if I leave the app,