Cordova geolocation not working if GPS is turned on after opening the app

When I turn on GPS on my phone before opening the app, geolocation works fine. But when I do it after, I keep getting the timeout error.

anyone knows how to solve this? thanks

UPDATE: if I exit the app without closing it and then come back to it, the geolocation starts working

Try using background geolocation plugin insted of geolocation