Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huge latency #254

Closed
canado opened this issue Nov 17, 2017 · 17 comments
Closed

huge latency #254

canado opened this issue Nov 17, 2017 · 17 comments
Labels
more info needed Further information is requested. If not provided, issue will be closed

Comments

@canado
Copy link

canado commented Nov 17, 2017

Hi,

I compiled my app few weeks ago and the GPS detection was working just fine.
I compiled yesterday and now it takes 2 to 3 min for the GPS to embark.

Can you look into the problem ?

Thanks

@dpa99c
Copy link
Owner

dpa99c commented Nov 17, 2017

This is by no means enough information to determine if there is an issue.

What platform (iOS/Android/Windows), platform version, plugin version, specific plugin functions are you testing?

What do you mean by "GPS detection" and "GPS to embark"?
Exactly which plugin functions does this relate to and what is the exact problem?

@dpa99c dpa99c added the more info needed Further information is requested. If not provided, issue will be closed label Nov 17, 2017
@canado
Copy link
Author

canado commented Nov 17, 2017

Ok so

Android,samsung s7 ( haven't tested on iOS yet )
cli-7.0.1 (4.4.0 / 6.2.3 / 5.0.0)

cordova.plugins.locationAccuracy.canRequest returns 0 instead of 1
my phone gps is activated

ifI try to do cordova.plugins.locationAccuracy.request even if canRequest = 0
I have code 2 message:application does not have sufficient geolocation permissions
But I guess this would be the normal message in that case

@canado
Copy link
Author

canado commented Nov 17, 2017

Also in my config.xml I have
<gap:plugin name="cordova-plugin-geolocation" source="npm"/>

but the thing is that everything was working just fine before and now it is not.
Were there big changes in the plugin code recently ?

@dpa99c
Copy link
Owner

dpa99c commented Nov 17, 2017

The functions in the cordova.plugins.locationAccuracy namespace are part of cordova-plugin-request-location-accuracy, not this plugin (cordova-diagnostic-plugin).

Were there big changes in the plugin code recently ?

As you can see from the commit history for cordova-plugin-request-location-accuracy, there were no changes since 29th August.

cordova.plugins.locationAccuracy.canRequest returns 0 instead of 1 my phone gps is activated

As the documentation states for canRequest(): "On Android, this will return true if the app has authorization to use location."

I.e. this bears no relation to whether your phone gps is activated

ifI try to do cordova.plugins.locationAccuracy.request even if canRequest = 0
I have code 2 message:application does not have sufficient geolocation permissions

This is to be expected if you call request() when the application does not have location permission.
Before you can call request(), you application must have run-time permission to use location on Android 6+. One way you can achieve this is by calling this plugin's requestLocationAuthorization() function.

Note you need to also ensure appropriate permissions are added to the AndroidManifest.xml - see here

@canado
Copy link
Author

canado commented Nov 17, 2017

Thank you for your reply.
Since I haven't changed my code and this plugin neither. What do you think could be the problem ?
I am using phonegap build to compile

@dpa99c
Copy link
Owner

dpa99c commented Nov 17, 2017

What do you think could be the problem ?

Probably Phonegap Build. When using remote build solutions such as this, you have no idea what they've changed in the build environment.

If you're using <config-file> blocks in your config.xml to insert <uses-permission> elements, note these are no longer supported as of Phonegap Build cli-7.0.1 see here. That would explain the sudden loss of permission to access location.

@canado
Copy link
Author

canado commented Nov 17, 2017

I tested on a friend's iPhone and it is working just fine. So it must be an android compiling problem

@dpa99c
Copy link
Owner

dpa99c commented Nov 17, 2017

The location accuracy plugin works completely differently on iOS and would not rely on <config-file> blocks in config.xml to insert <uses-permission> for location permission.

@canado
Copy link
Author

canado commented Nov 17, 2017

I am not using in my config.xml

But I am using this
<gap:plugin name="cordova-plugin-geolocation" source="npm"/>
<gap:plugin name="cordova-plugin-request-location-accuracy" source="npm"/>

@dpa99c
Copy link
Owner

dpa99c commented Nov 17, 2017

cordova-plugin-geolocation should insert the <uses-permission> entries then.

I'd highly recommend moving to a local build environment instead of Phonegap Build as it puts you in complete control of your build environment.
Since you're using Phonegap Build, it's not possible to do any debugging during the build process, so you will need to debug on the device.

You can debug the Cordova app running inside the Webview using Chrome Dev Tools and the native plugin using Android Studio.

@canado
Copy link
Author

canado commented Nov 17, 2017

I completely understand, and it starts to get on my nerves to be honest.

@canado
Copy link
Author

canado commented Nov 17, 2017

Sorry to bother you again

I did some digging, and I am still stuck on android.I have done a blank app with just the geolocation

Can you confirm that what I do is correct ?

first I do

    cordova.plugins.locationAccuracy.canRequest(function(canRequest) {

        //canRequest is always 0 even if the phone location is on or not. I don't know if this is normal.

        if (canRequest) {

        } else {

            cordova.plugins.locationAccuracy.request(function(success) {


                /*Here it successfully come this far*/

                var geoOptions = {
                    enableHighAccuracy: true
                };
                navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, geoOptions);

                //then it goes inside geolocationError function.
                // and in there it says that the permissions are not set. But even when I do cordova.plugins.diagnostic.switchToLocationSettings(); I can see that the location permission is on, which is wierd.

            }, function(error) {
                alert("error");
                alert(JSON.stringify(error, null, 4));

            }, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);


        }

    });

@canado
Copy link
Author

canado commented Nov 17, 2017

Also I have cloned your project https://github.com/dpa99c/cordova-plugin-request-location-accuracy-example.git

and installed it, and it is not working. even when I switch on/off location.
I am tapping on all 3 buttons

request location
request location authorization
open app settings

and it does nothing.

@dpa99c
Copy link
Owner

dpa99c commented Nov 18, 2017

Also I have cloned your project and installed it, and it is not working. even when I switch on/off location.

Presumably you tried building it with Phonegap Build which will not work because the example project uses a <config-file> block to add the necessary <uses-permission> entries, which (as mentioned above) are no longer supported by Phonegap Build.

Phonegap Build (like other "cloud" build services) is a 2nd class build enviroment compared with building locally, where you have full control of the source code and build environment.
It lacks core features of Cordova/Phonegap available when building locally: for example, hook scripts which do not work in Phonegap Build.
If you're doing anything more than a basic/trivial app, you should build locally.

Can you confirm that what I do is correct ?

No, it's not. By calling cordova.plugins.locationAccuracy.canRequest() before you call the Geolocation plugin, (navigator.geolocation.getCurrentPosition()) you have no run-time authorisation to use location, hence canRequest() returns 0.

As I said above, you need to manually request run-time authorisation via the diagnostic plugin, something like this:

function proceed() {
    cordova.plugins.locationAccuracy.canRequest(function(canRequest) {
        if (canRequest) {} else {
            cordova.plugins.locationAccuracy.request(function(success) {

                var geoOptions = {
                    enableHighAccuracy: true
                };
                navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, geoOptions);

            }, function(error) {
                alert("error");
                alert(JSON.stringify(error, null, 4));

            }, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
        }
    });
}

function onError(error) {
    console.error("The following error occurred: " + error);
}

function handlePermissionResult(status) {
    switch (status) {
        case cordova.plugins.diagnostic.permissionStatus.GRANTED:
            console.log("Permission granted");
            proceed();
            break;
        case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
            console.log("Permission not requested");
            requestPermission();
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED:
            console.log("Permission denied");
            requestPermission();
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
            console.log("Permission permanently denied");
            // Notify user and switch to settings to manually enable
            break;
    }
}

function checkPermission() {
    cordova.plugins.diagnostic.getLocationAuthorizationStatus(handlePermissionResult, onError);
}

function requestPermission() {
    cordova.plugins.diagnostic.requestLocationAuthorization(handlePermissionResult, onError);
}

checkPermission(); // start with checking permission

@canado
Copy link
Author

canado commented Nov 18, 2017

Good morning,

Thank you so much for the code.
I tried it ( I just replaced console.log by alerts );

before I launch the app I activate the gps localisation.

then I have in this order

Permission not requested
Permission granted
geolocationError ( in my own function )
code:2
message: application does not have sufficient geolocation permissions.

: (

@canado
Copy link
Author

canado commented Nov 19, 2017

Found it, the new pgb compiling setup is no more including location permissions in the androidmanifest !!!

Thanks again for the help, it's really appreciated.

@dpa99c
Copy link
Owner

dpa99c commented Nov 19, 2017

Closing this on the basis that the solution is you should not use Phonegap Build

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed Further information is requested. If not provided, issue will be closed
Projects
None yet
Development

No branches or pull requests

2 participants