nativescript-community / gps

Tracks GPS location updates regardless of the app state. Does not depend on Google Play Services.
https://nativescript-community.github.io/gps/
Other
10 stars 2 forks source link

TypeError: androidLocation.getProvider is not a function #19

Open LaKing opened 2 years ago

LaKing commented 2 years ago
System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onLocationChanged failed
System.err: TypeError: androidLocation.getProvider is not a function
System.err: 
System.err: StackTrace:
System.err: locationFromAndroidLocation(file: app/webpack:/Hangmaffia/node_modules/@nativescript-community/gps/gps.android.js:101:0)
System.err:     at onLocationChanged(file: app/webpack:/Hangmaffia/node_modules/@nativescript-community/gps/gps.android.js:36:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.android.location.LocationListener.onLocationChanged(LocationListener.java:24)
System.err:     at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3196)
System.err:     at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3193)
System.err:     at com.android.internal.listeners.ListenerExecutor.lambda$executeSafely$0(ListenerExecutor.java:127)
System.err:     at com.android.internal.listeners.ListenerExecutor$$ExternalSyntheticLambda0.run(Unknown Source:8)
System.err:     at android.os.Handler.handleCallback(Handler.java:938)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loopOnce(Looper.java:226)
System.err:     at android.os.Looper.loop(Looper.java:313)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:8582)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
System.err: java.lang.reflect.InvocationTargetException
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.tns.NativeScriptUncaughtExceptionHandler.uncaughtException(NativeScriptUncaughtExceptionHandler.java:58)
System.err:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073)
System.err:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
System.err:     at java.lang.Thread.dispatchUncaughtException(Thread.java:2200)
System.err: Caused by: java.lang.IllegalArgumentException: org.nativescript.Hangmaffia: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
System.err: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
System.err:     at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
System.err:     at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
System.err:     at android.app.PendingIntent.getActivity(PendingIntent.java:451)
System.err:     at android.app.PendingIntent.getActivity(PendingIntent.java:415)
System.err:     at com.tns.ErrorReport.startPendingErrorActivity(ErrorReport.java:157)
System.err:     at com.tns.ErrorReport.startActivity(ErrorReport.java:136)
System.err:     ... 5 more

Which platform(s) does your issue occur on?

I see this corrently on the latest Android version, with a physical device. Android 12

Please, provide the following version numbers that your issue occurs with:

### Code
```javascript
const gps = new GPS();

        gps.debug = true;
        const auth = await gps.isAuthorized();

        let location = await gps.getCurrentLocation({
            timeout: 2000,
        });

The app is crashing here.

If using skipPermissionCheck: true then the app doesn't crash, but there are no gps coordinates.

farfromrefug commented 2 years ago

@LaKing i have fixed the issue in 3.1.1 however it means the native side reported a "null" location which should not happen. Maybe you are missing permissions

LaKing commented 2 years ago

Thank you @farfromrefug ... I added myself to your sponsors .)

farfromrefug commented 2 years ago

@LaKing wow thank you! Dont hesitate to find me on discord if you have issues with getting locations on android 12. Can we close this?

LaKing commented 2 years ago

@farfromrefug Yes, the error is gone now ... my app still crashes, but at least there are no build errors now. Let's meet on the plugins channel! ...

Thanks!!

LaKing commented 2 years ago

Reproducing in a minimal code

ns create my-tab-vue --template @nativescript/template-tab-navigation-vue cd my-tab-vue tns plugin add @nativescript-community/gps

Edit AndroidManifest to add permissions

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application ...

Edit AndroidManifest to add within the application block

<activity
            android:exported="true"
...

Edit app/components/App.vue and in the script tag put the following content

import Items from "./Items.vue";
import Browse from "./Browse.vue";
import Search from "./Search.vue";
import { GPS } from "@nativescript-community/gps";
export default {
    components: {
        Items,
        Browse,
        Search,
    },
    created() {
        console.log("------------@ created--------------");
        async function test() {
            console.log("----------- @ test---------------");

            const gps = new GPS();

            gps.debug = true;

            if (!gps.isEnabled()) {
                console.log("---------- @ Location not enabled, requesting. -----------");
                return gps
                    .authorize(true)
                    .then(() => gps.enable())
                    .then(() => gps.isEnabled());
            }

            const auth = await gps.isAuthorized();

            console.log(" --------------- GPS getLocation: authorized", auth, "--------------");

            const location = await gps.getCurrentLocation({
                timeout: 2000,
                //skipPermissionCheck: true
            });
            console.log("------------ @ location--------------", location);
        }
        test();
    },
};

Eventually edit `app.js

Vue.config.silent=false;

With a physical android device connected run, ...

tns run

The application requests the GPS permissions. Once the permission is given, restart the application / run tns run again it will crash on sturtup after our GPS getLocation: authorized true .. and then crashes at every subsequent startup.

tns debug android
NachmanRoss commented 2 years ago

I'm using the 3.1.1 version and the plugin is failing to return my location on android. It works fine on iOS. I'm using the latest alpha versions of cli, android, and core. I'm seeing this in my sdk 31 emulator and on my samsung phone - Android 12. I also ask for permissions when the app starts and allow when using the app. I am seeing the error listed above: System.err: Calling js method onLocationChanged failed System.err: TypeError: androidLocation.getProvider is not a function

I'm requesting the location as follows (I'm not setting skipPermissionCheck: true) but I don't know what the default is. SelectedPageService.gps.getCurrentLocation( { desiredAccuracy: CoreTypes.Accuracy.high, maximumAge: 5000, timeout: 5000 }).then((location) => { if (location) { console.log("updating location to latitude: " + location.latitude + " longitude: " + location.longitude); } else { console.log("current location returned as null"); }

LaKing commented 2 years ago

@NachmanRoss you could contact @farfromrefug or other maintainers on discord, and debug the issue. The code for the minimal reproduction is above. ....

Would be nice to get this plugin working, I'm using another GPS plugin for now.

farfromrefug commented 2 years ago

@NachmanRoss you need to debug this. in the error stack it tells you where the error happens. there add a console.log of the androidLocation before the access to getProvider to see what is androidLocation. We need to know

LaKing commented 2 years ago

@farfromrefug Since the problem can be reproduced in an empty project, it does not make sense to ask users of the plugin to debug this in their projects. The plugin is broken in general, and not in a specific project.

NachmanRoss commented 2 years ago

I agree with LaKing. I only have one place where I call the plugin to get the location and the code for that is shown above. I also for permission to use it in this one place: if (!SelectedPageService.gps.isEnabled()) { return SelectedPageService.gps .authorize(true) .then(() => SelectedPageService.gps.enable()) .then(() => SelectedPageService.gps.isEnabled()); } else { return Promise.resolve(true); }

The error that I see in the log is when the android app is launched after being sent into background in this code from my app.ts file: Application.on(Application.uncaughtErrorEvent, (args) => { console.log("Uncaught Error: " + args.error.stack); if (args.android) { console.log("Nativescript Error: " + args.android); } else { console.log("Nativescript Error: " + args.ios); } });

So I never call the getProvider myself. It is being triggered when the app is brought into the foreground on android. It's probably happening during the getCurrentLocation call and is probably something that the android app is losing a pointer to when it is sent to the background.

farfromrefug commented 2 years ago

@LaKing @NachmanRoss i have that plugin working in production in around five apps. and me have sessions running in background for.more than 8 hours. there are many reasons why this might not work for you which i cant always reproduce. bit if you dont want to help sure dont i cant force you.

about the issue i am helping blind here. did you add everyhting necessary in your manifest file ?

NachmanRoss commented 2 years ago

I'm not unwilling to help but I don't know how to help. I've literally posted the only two places that I explicitly call the plugin. Both are localized to one class. One call to get authorization and the other call to getCurrentLocation. The trace log that is printed by the Application.on(Application.uncaughtErrorEvent doesn't mention my class or my use of getCurrentLocation. So I'm at a loss. My androidManifest has the following entries:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

When the app starts (for the first time after a new install), I'm asked to grant permission and I select "when the app is in use" and "Fine Location". I don't need the gps running in background so I don't ask for that permission. I only try to get the location when the user goes to the app's main menu. The action is probably also triggered when the device is brought to the foreground. This error didn't occur in the past and I believe started happening when I switched to the latest alpha versions of nativescript. It works fine with iOS.

I'm willing to install a debug version of the plugin with more error messages and try that but otherwise I'm not sure where to begin to look on my own. None of the statements listed in the trace log are from my classes or code. They're all from within the plugin and its internal calls.

LaKing commented 2 years ago

@farfromrefug can you please check if you can reproduce the issue with the minimal code for reproduction?

Reproducing in a minimal code

ns create my-tab-vue --template @nativescript/template-tab-navigation-vue cd my-tab-vue tns plugin add @nativescript-community/gps

Edit AndroidManifest to add permissions

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application ...

Edit AndroidManifest to add within the application block

<activity
            android:exported="true"
...

Edit app/components/App.vue and in the script tag put the following content

import Items from "./Items.vue";
import Browse from "./Browse.vue";
import Search from "./Search.vue";
import { GPS } from "@nativescript-community/gps";
export default {
    components: {
        Items,
        Browse,
        Search,
    },
    created() {
        console.log("------------@ created--------------");
        async function test() {
            console.log("----------- @ test---------------");

            const gps = new GPS();

            gps.debug = true;

            if (!gps.isEnabled()) {
                console.log("---------- @ Location not enabled, requesting. -----------");
                return gps
                    .authorize(true)
                    .then(() => gps.enable())
                    .then(() => gps.isEnabled());
            }

            const auth = await gps.isAuthorized();

            console.log(" --------------- GPS getLocation: authorized", auth, "--------------");

            const location = await gps.getCurrentLocation({
                timeout: 2000,
                //skipPermissionCheck: true
            });
            console.log("------------ @ location--------------", location);
        }
        test();
    },
};

Eventually edit `app.js

Vue.config.silent=false;

With a physical android device connected run, ...

tns run

The application requests the GPS permissions. Once the permission is given, restart the application / run tns run again it will crash on sturtup after our GPS getLocation: authorized true .. and then crashes at every subsequent startup.

tns debug android
farfromrefug commented 2 years ago

@NachmanRoss thanks for wanting to help. as i said in an earlier post, as i cant reproduce it here what i need is for you to reproduce the issue after adding a console log. if you have a callstack like mentioned in the firstpost then the callstack tells you where yhe error is happening (function/line/file). what would help me is to add a console.log right before the actual error (before line 101). in that console log it would nice to do something like console.log("test", androidLocation, androidLocation.constructor.name, androidLocation.getProvider); that would help a lot

farfromrefug commented 2 years ago

@NachmanRoss just saw you mentioned the new alpha of N. can you try to rollback ? does it work ? what version of N exactly? they did some heavy and for some broken changes.

NachmanRoss commented 2 years ago

Here are my current versions: "@nativescript/core": "8.2.0-custom.0", "devDependencies": { "@nativescript/android": "^8.2.0-alpha.11", "@nativescript/ios": "^8.2.0-custom.0", "@nativescript/types": "^8.1.1", "@nativescript/webpack": "^5.0.4", "typescript": "^4.5.5" }, my cli is 8.1.5-next-12-23-2021-1617049163

I might be able to rollback except that other functionalities that my app has require a gradle 7 build which is why I started using the alpha packages.

I can attempt with the minimal code but I'm not familiar with vue. I can attempt to reproduce the minimal version but as a straight typescript project. Is that possible and would I replace app.vue with app.ts?

farfromrefug commented 2 years ago

@NachmanRoss are we talking abiut the runtime or the core ? please can you details what version it works with and which it does not ?

NachmanRoss commented 2 years ago

My app doesn't work on android with the versions I listed above your last comment. The same app works perfectly in iOS with the above versions.

I also attempted to create a minimal version using the ns create command. I created a typescript project using the Hello World template. I then added the AndroidManifest entries and the gps plugin. I also updated to the same @nativescript/core, @nativescript/android, @nativescript/ios, and @nativescript/webpack shown above. My ns -version reports: 8.1.5-next-12-23-2021-1617049163.

The problem is that it builds without errors but when I try to run it using ns run android, I get the following error that I've never seen before although I've created and run many apps over the years: Here's the lines in my terminal window showing the results of the build and the attempt to run the app.

webpack 5.68.0 compiled successfully in 185 ms Webpack compilation complete. Watching for file changes. Issues checking in progress...

I have no clue as to why the app won't run on the emulator. It shows as an installed app on the emulator but even if I tap on it and try to start it manually it crashes. So I can't reproduce the error in order to send you the log trace.

NachmanRoss commented 2 years ago

Ok. I was able to get the minimal typescript app running and it throws the following when I tap on the Tap Button in the main-view-model.ts which runs the getCurrentLocation function: JS: gps is enabled ... getting current location System.err: An uncaught Exception occurred on "main" thread. System.err: Calling js method onLocationChanged failed System.err: TypeError: androidLocation.getProvider is not a function System.err: System.err: StackTrace: System.err: locationFromAndroidLocation(file: app/webpack:/org.nativescript.testgps/node_modules/@nativescript-community/gps/gps.android.js:104:0) System.err: at onLocationChanged(file: app/webpack:/org.nativescript.testgps/node_modules/@nativescript-community/gps/gps.android.js:39:0) System.err: at com.tns.Runtime.callJSMethodNative(Native Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302) System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1175) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1153) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1149) System.err: at com.tns.gen.android.location.LocationListener.onLocationChanged(LocationListener.java:24) System.err: at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3180) System.err: at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3177) System.err: at com.android.internal.listeners.ListenerExecutor.lambda$executeSafely$0(ListenerExecutor.java:127) System.err: at com.android.internal.listeners.ListenerExecutor$$ExternalSyntheticLambda0.run(Unknown Source:8) System.err: at android.os.Handler.handleCallback(Handler.java:938) System.err: at android.os.Handler.dispatchMessage(Handler.java:99) System.err: at android.os.Looper.loopOnce(Looper.java:201) System.err: at android.os.Looper.loop(Looper.java:288) System.err: at android.app.ActivityThread.main(ActivityThread.java:7839) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) JS: Uncaught Error: locationFromAndroidLocation(file: app/webpack:/org.nativescript.testgps/node_modules/@nativescript-community/gps/gps.android.js:104:0) JS: at onLocationChanged(file: app/webpack:/org.nativescript.testgps/node_modules/@nativescript-community/gps/gps.android.js:39:0) JS: Nativescript Error: Error: Calling js method onLocationChanged failed JS: TypeError: androidLocation.getProvider is not a function System.err: java.lang.reflect.InvocationTargetException System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.tns.NativeScriptUncaughtExceptionHandler.uncaughtException(NativeScriptUncaughtExceptionHandler.java:58) System.err: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073) System.err: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) System.err: at java.lang.Thread.dispatchUncaughtException(Thread.java:2200) System.err: Caused by: java.lang.IllegalArgumentException: org.nativescript.testgps: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. System.err: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. System.err: at android.app.PendingIntent.checkFlags(PendingIntent.java:375) System.err: at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458) System.err: at android.app.PendingIntent.getActivity(PendingIntent.java:444) System.err: at android.app.PendingIntent.getActivity(PendingIntent.java:408) System.err: at com.tns.ErrorReport.startPendingErrorActivity(ErrorReport.java:157) System.err: at com.tns.ErrorReport.startActivity(ErrorReport.java:136) System.err: ... 5 more

NachmanRoss commented 2 years ago

I hope this helps and I can zip up the app (minus the node_modules, platforms, and anything else that will be generated by the build command) and send it to you if you want.

farfromrefug commented 2 years ago

@NachmanRoss You are running this on a 31 api level emulator? Cause i think this is your error:

System.err: Caused by: java.lang.IllegalArgumentException: org.nativescript.testgps: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
System.err: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Though this plugin does not use PendingItent :s

EDIT: yes please share the app

NachmanRoss commented 2 years ago

Archive.zip

Here's the zip file. Its only 189 KB If you don't get it let me know and maybe I can send it via Discord

NachmanRoss commented 2 years ago

Yes. I'm running it on a 31 level emulator and on my android phone using Android 12.

farfromrefug commented 2 years ago

@NachmanRoss @LaKing it should be fixed in 3.1.2. It was due to some API changes in android 12. Sorry for the trouble

NachmanRoss commented 2 years ago

I added the new version and did an ns clean. Yet in my emulator the location is still returning as null and on my phone it doesn't appear to be working either. I'll see if I can spot any errors later this morning as I have to take a break for the next hour. Thanks for the work that you're putting into this.

farfromrefug commented 2 years ago

@NachmanRoss weird i tried on a 31 emulator and it worked just fine. But about the null thing might be something else. Please add this in your app main file

import { Application, Trace } from '@nativescript/core'
import { GPSTraceCategory } from '@nativescript-community/gps'

Trace.addCategories(GPSTraceCategory)
Trace.enable()

and send me what you get when the null is returned

NachmanRoss commented 2 years ago

Here's what I'm getting in my full blown app with the extra trace statements added to app.ts.

JS: about to process request to get current location JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: checking message registration... JS: Firebase messaging has permission JS: Firebase messaging has permission JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: current location returned as null

I'll also try this on the minimal version of the app that I sent you yesterday.

farfromrefug commented 2 years ago

@NachmanRoss ok you simply timeout with no location found!

NachmanRoss commented 2 years ago

I ran it in the minimal app and I'm getting this trace which looks strange to me because it seems to be finding the emulator's location yet it says that the location is null. Here's the trace and the code that I'm running: JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329133,"longitude":-73.7198567,"altitude":-0.07047204006029573,"horizontalAccuracy":5,"speed":0,"bearing":0,"verticalAccuracy":3,"timestamp":1644602254760,"age":28647,"elapsedBoot":287815769,"android":{}}] JS: current location returned as null

Here's the code I'm running: getCurrentLocation() { if (this.gps.isEnabled()) { console.log("gps is enabled ... getting current location"); this.gps.getCurrentLocation( { desiredAccuracy: CoreTypes.Accuracy.high, maximumAge: 5000, timeout: 5000 }).then((location) => { if (location) { console.log("updating location to latitude: " + location.latitude + " longitude: " + location.longitude); } else { console.log("current location returned as null"); } }).catch((err) => { console.log("getting current location failed with err: " + err); }) } else { console.log("geolocation is not enabled"); } }

Am I making the call incorrectly? And why doesn't my full blown app show the same message onLocationChanged that the minimal app shows? They both use the same call and are running on the same emulator.

farfromrefug commented 2 years ago

@NachmanRoss ok it is still normal "in a sense" the location is returned is seen as too old as it has an age of 28647 ms which is higher than what you asked for. Though when i look at the timestamp it does not seem right to me, Same for the elapsedBoot. Will need to create a new version with more logs to debug this.

farfromrefug commented 2 years ago

@NachmanRoss can you send me the log with 3.1.3 ?

NachmanRoss commented 2 years ago

Do you mean a plugin version of 3.1.3? I just tested with the 3.1.2 version because that’s the version that you posted had the fix. @.**@. it should be fixed in 3.1.2. It was due to some API changes in android 12. Sorry for the trouble"

I didn’t check if there was a 3.1.3 version. Let me try with the 3.1.3 version. Also what I sent you was in effect the only log that I am seeing in the console. Do you want me to add some other log statements? Let me know and I’ll try whatever you suggest. Meanwhile I’ll try with the 3.1.3 version ad if it doesn’t work, I’ll increase the timeout and see if that helps.

Nachman Beinish Ross On Feb 14, 2022, 9:20 AM -0500, farfromrefuge @.***>, wrote:

@NachmanRoss can you send me the log with 3.1.3 ?

— Reply to this email directly, view it on GitHub https://github.com/nativescript-community/gps/issues/19#issuecomment-1039135710 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AKUWSSYL2HTHUSGWJV7LC5TU3EE67ANCNFSM5JQ7ZNYA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AKUWSS4TBYHQ4AMFKQ65USLU3EE67A5CNFSM5JQ7ZNYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHXX7HXQ.gif Message ID: @.***>

farfromrefug commented 2 years ago

@NachmanRoss just the same exact test for you with 3.1.3. There will be more logs

NachmanRoss commented 2 years ago

I tried with the 3.1.3 version and added the time when the call returns after the timeout period. It worked once and failed twice yet it's the same call being invoked when the user taps on a button.:

JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290946134,"currentTimeMillis":1644605385124,"bootTime":1644314438990,"sinceBoot":290941302955179} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329133,"longitude":-73.7198567,"altitude":0.036517788224621595,"horizontalAccuracy":5,"speed":0,"bearing":0,"verticalAccuracy":3,"timestamp":1644605380293,"age":4832,"elapsedBoot":290941303,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290946134,"currentTimeMillis":1644605385125,"bootTime":1644314438991,"sinceBoot":290941302955179} JS: returned at: 1644605385138 updating location to latitude: 40.6329133 longitude: -73.7198567 JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3

JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290959541,"currentTimeMillis":1644605398532,"bootTime":1644314438991,"sinceBoot":290941302955179} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329133,"longitude":-73.7198567,"altitude":0.036517788224621595,"horizontalAccuracy":5,"speed":0,"bearing":0,"verticalAccuracy":3,"timestamp":1644605380294,"age":18238,"elapsedBoot":290941303,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290959542,"currentTimeMillis":1644605398533,"bootTime":1644314438991,"sinceBoot":290941302955179} JS: returned at: 1644605403528 current location returned as null JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3

JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290991786,"currentTimeMillis":1644605430776,"bootTime":1644314438990,"sinceBoot":290941302955179} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329133,"longitude":-73.7198567,"altitude":0.036517788224621595,"horizontalAccuracy":5,"speed":0,"bearing":0,"verticalAccuracy":3,"timestamp":1644605380293,"age":50483,"elapsedBoot":290941303,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644605380285,"elapsedRealtime":290991786,"currentTimeMillis":1644605430777,"bootTime":1644314438991,"sinceBoot":290941302955179} JS: returned at: 1644605435769 current location returned as null

farfromrefug commented 2 years ago

@NachmanRoss i think the time in your emulator is set to 3 days old. Not a big deal but so you know ;) as for the rest everything seems normal. Just the returned location is too old seeing your parameters

NachmanRoss commented 2 years ago

I feel like a real idiot for not noticing that. I installed the minimal app on my phone and it works most of the time. Then I tried it in my full blown app and noticed that it also works intermittently. So I added your trace statements and attached my phone to my mac and tested on it. Here's the log showing how one call works and the other fails. Could it be that I'm triggering the calls too many times in a short period of time and they're interfering with each other?

JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644862647231,"elapsedRealtime":151408691,"currentTimeMillis":1644862647280,"bootTime":1644711238589,"sinceBoot":151408642000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329371,"longitude":-73.7199739,"altitude":-29.100000381469727,"horizontalAccuracy":20,"verticalAccuracy":1.3166667222976685,"timestamp":1644862647231,"age":49,"elapsedBoot":151408642,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644862647231,"elapsedRealtime":151408691,"currentTimeMillis":1644862647280,"bootTime":1644711238589,"sinceBoot":151408642000000} JS: returned at: 1644862647281 current location is latitude: 40.6329371 logitude: -73.7199739 JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644862647284,"elapsedRealtime":151419055,"currentTimeMillis":1644862657644,"bootTime":1644711238589,"sinceBoot":151408695000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329371,"longitude":-73.7199739,"altitude":-29.100000381469727,"horizontalAccuracy":20,"verticalAccuracy":1.3166667222976685,"timestamp":1644862647284,"age":10360,"elapsedBoot":151408695,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644862647284,"elapsedRealtime":151419055,"currentTimeMillis":1644862657644,"bootTime":1644711238589,"sinceBoot":151408695000000} JS: returned at: 1644862662645 current location returned as null

I can try adding logic to skip the call if the time of the call is within a minute of an earlier call but maybe you have a better idea.

farfromrefug commented 2 years ago

@NachmanRoss no it is not normal it should return. could you try and reproduce in the sample app?

NachmanRoss commented 2 years ago

This is my sample app where I tap the button to get the coordinates repeatedly. You can see the first call works and the others eventually return null.

JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153498297,"currentTimeMillis":1644864736886,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329375,"longitude":-73.719978,"altitude":-29.100000381469727,"horizontalAccuracy":11.819000244140625,"speed":0.006555020809173584,"bearing":64.3979263305664,"verticalAccuracy":1.283333420753479,"timestamp":1644864733297,"age":3589,"elapsedBoot":153494708,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153498298,"currentTimeMillis":1644864736886,"bootTime":1644711238588,"sinceBoot":153494708000000} JS: returned at: 1644864736887 updating location to latitude: 40.6329375 longitude: -73.719978 JS: JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153499806,"currentTimeMillis":1644864738395,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329375,"longitude":-73.719978,"altitude":-29.100000381469727,"horizontalAccuracy":11.819000244140625,"speed":0.006555020809173584,"bearing":64.3979263305664,"verticalAccuracy":1.283333420753479,"timestamp":1644864733297,"age":5098,"elapsedBoot":153494708,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153499806,"currentTimeMillis":1644864738395,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153500662,"currentTimeMillis":1644864739251,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329375,"longitude":-73.719978,"altitude":-29.100000381469727,"horizontalAccuracy":11.819000244140625,"speed":0.006555020809173584,"bearing":64.3979263305664,"verticalAccuracy":1.283333420753479,"timestamp":1644864733297,"age":5954,"elapsedBoot":153494708,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153500662,"currentTimeMillis":1644864739251,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: JS: about to call getCurrentLocation() JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: gps is enabled ... getting current location JS: N-GPS: getCurrentLocation {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: prepareForRequest {"desiredAccuracy":3,"maximumAge":5000,"timeout":5000} true JS: N-GPS: isAuthorized JS: N-GPS: isAuthorized result ["authorized",true] JS: N-GPS: enabled provider: passive JS: N-GPS: enabled provider: network JS: N-GPS: enabled provider: fused JS: N-GPS: enabled provider: gps JS: N-GPS: isLocationServiceEnabled 4 4 3 JS: N-GPS: createLocationListener 31 JS: N-GPS: requestLocationUpdates 60000 0 {} true JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153504405,"currentTimeMillis":1644864742993,"bootTime":1644711238588,"sinceBoot":153494708000000} JS: N-GPS: onLocationChanged [{"provider":"fused","latitude":40.6329375,"longitude":-73.719978,"altitude":-29.100000381469727,"horizontalAccuracy":11.819000244140625,"speed":0.006555020809173584,"bearing":64.3979263305664,"verticalAccuracy":1.283333420753479,"timestamp":1644864733296,"age":9698,"elapsedBoot":153494708,"android":{}}] JS: N-GPS: locationFromAndroidLocation {"getTime":1644864733297,"elapsedRealtime":153504405,"currentTimeMillis":1644864742994,"bootTime":1644711238589,"sinceBoot":153494708000000} JS: returned at: 1644864743394 current location returned as null JS: returned at: 1644864744251 current location returned as null JS: returned at: 1644864747998 current location returned as null

NachmanRoss commented 2 years ago

I also updated my full blown app and installed the release .apk version so that it does the following check: let timeNow: number = Date.now(); if (timeNow - SelectedPageService.lastGpsCheck > 60000) {

If the current time is greater than the lastCheck + 60000, it gets the coordinates from the plugin and saves them. If the check is within the last minute, it returns the saved coordinates instead of asking the plugin to get them. With that change, the app initially didn't get the coordinates but it is working now.

NachmanRoss commented 2 years ago

I spoke too soon. The full blown app is still failing to get the coordinates on a reliable basis. It is working sometimes but not every time.