For a customer, we had a very similar requirement: trace the location of a mobile phone while the Mendix app is not running, or is in the background. The best solution we currently have is by using a built for purpose app: traccar, which also requires a server, available in the Google Play store. We did try to tackle this requirement in Mendix, but it just didn't function well enough.
Note that, even with this specific app, you have two (potential) problems:
* The battery drains notably faster
* The GPS position reported by a mobile phone is rather inaccurate (this may not be a problem if you do not require very accurate data)
We have used a opensource app called Traccar which runs in the background. This app was forwarding the geolocation of the user to our Mendix app where we processed the data (in our case we used the GEO features of Redis). Positions of the user could easily shown with the Google Maps widget in Mendix.
You can check out the google maps widget. I believe it has a get current location feature.
Hope this helps!
If it is for a european customer: mind the GDPR-regulations.