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

'minimumUpdateTime' in seconds, not milliseconds #20

Closed chris-praxis closed 2 years ago

chris-praxis commented 2 years ago

I've been using 'watchLocation' to get updates on iOS, but when I tried on Android it was not working until I set 'minimumUpdateTime' to a small number (e.g. 1-5). Apparently this number is in seconds. Looking in "gps.android.js", I see that the default is in milliseconds: const minTimeUpdate = 1 60 1000;

Which platform(s) does your issue occur on?

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

Start watching for location changes and print whenever you get them. If 'minimumUpdateTime' is not set, then I don't get location update prints. If I set it to one for instance, then I get updates about every second.

(in data)
gps: new GPS()

            startLocationListener()
            {
                if(!this.gps.hasGPS())
                    return;

                let _this = this;
                let props = App.ios
                    ? {
                        allowsBackgroundLocationUpdates: true,
                        pausesLocationUpdatesAutomatically: false
                    }
                    : {
                        minimumUpdateTime: 1 // seconds
                    }; // android

                this.isWaiting = true;
                this.gps.watchLocation(this.locationCB, this.locationErrorCB, props)
                .then(id => {
                    _this.watchLocationId = id;
                    _this.isWaiting = false;
                })
                .catch(err => {
                    console.error("failed to start location listener: "+err);
                    _this.isWaiting = false;
                });
            },

            locationCB(location)
            {
                console.log("*** got location: "+location.longitude+", "+location.latitude);
            },
farfromrefug commented 2 years ago

@chris-praxis i confirm minUpdateTime is in ms and is working as expected. I am not saying there is not an issue but it does not come from there. I use 1000 in all my apps and it correctly updates every 1s. I ll post the code I use Here is my code https://github.com/Akylas/jule_verne/blob/master/app/handlers/GeoHandler.ts#L1084

chris-praxis commented 2 years ago

@farfromrefug Thank you for sharing code, that was helpful. After further testing, my problem is not seconds vs milliseconds. Instead, I seem to be hitting a hard minimum. If I do not provide 'minimumUpdateTime', then I get GPS location every 60s as expected from the default. If I set 'minimumUpdateTime = 10000', then I get GPS location every 10s as expected. If I set 'minimumUpdateTime = 1000', as you have, I get GPS location every 5-6s. If I set 'minimumUpdateTime = 1' as I was doing, then I get GPS location every 5-6s.