This is my example of using GPS in Android device, this application will every user defined seconds (default 30) save a file with GPS longitude/latitude as a JSON node.

Please note that it was only tested with Huawei P30 lite, and Android 10, also please note that the files will never be deleted, you have to delete them manually. Files are located somewhere in \Android\data\com.milosev.justanotherrealtimetrackingapp\files\locations.

Source code download from here, APK from here, GitHub here.