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

Turning Location services on after timeout #109

Closed
Danbardo opened this issue Aug 19, 2018 · 13 comments
Closed

Turning Location services on after timeout #109

Danbardo opened this issue Aug 19, 2018 · 13 comments

Comments

@Danbardo
Copy link

Hi,

I am currently fixing some kinks with the geolocation in an application I am making.

As soon as the application boots, it calls the getCurrentLocation function.

I have noticed that if I open the application with location services disabled, then turn it on a few second after load, or after a TIMEOUT error, later calls of getCurrentLocation function do not work.

Typically I see that when I run the getCurrentLocation function, the GPS icon flashes in the statusbar of the phone, and the success method is executed. However, if a run the getCurrentLocation function after a TIMEOUT, or loading the application with location services off then turning them on later, the GPS icon does not appear and the error method is executed.

Does anyone have a solution to resolve this behavior?

Thanks

@janpio janpio added the support label Aug 19, 2018
@janpio
Copy link
Member

janpio commented Aug 19, 2018

What platform?

@Danbardo
Copy link
Author

Sorry, Andoid 8.0.0.

Haven't tested on iOS yet.

@janpio
Copy link
Member

janpio commented Aug 19, 2018

Is this consistent on other Android versions as well?
Can it be reproduced in an emulator?

@Danbardo
Copy link
Author

I have reproduced the problem with an older device which is using 5.0.1.

Unfortunately I can't isolate the problem.

I have rebuilt the project several times and the new projects never exhibit the same behavior. Everything between projects is identical, I am not sure why the original project is causing the issue.

@janpio
Copy link
Member

janpio commented Aug 20, 2018

(Anecdotally I have read/heard multiple times that geolocation is fishy when the app is started without the permissions and only then added - but afaik nobody was ever able to give a good reproduction case :( )

@Danbardo
Copy link
Author

Danbardo commented Aug 27, 2018

This issue is frequently occuring for me now, I am not sure why, but now I can't get fix it, here are the steps I take to reproduce it:

cordova create test --id "com.test.test" --name "test"
cd test
cordova plugin add cordova-plugin-geolocation

Delete everything in the init.js and replace with:

document.addEventListener("deviceready",function(){
	getGps();
},false);
function getGps(){
	navigator.geolocation.getCurrentPosition(gpsSuccess, gpsError,{timeout:5000,maximumAge:10000,enableHighAccuracy:true});
}
function gpsSuccess(position) {
	alert('Success');

}
function gpsError(error) {
	alert('GPS Error: code: '+error.code+'\n'+'message:'+error.message+'\n');
	getGps();
}
cordova platform add android@7.1.1
cordova run android

Turn Location on before running the application, you will see it works.
Exit the application.
Turn Location off.
Re-enter the application.
Wait for the timeout alert.
Turn Location on.
Notice that the application never accesses the location.

Tested on Android 8.0.0 and 5.0.1

@janpio
Copy link
Member

janpio commented Aug 27, 2018

Turn Location on.
Notice that the application never accesses the location.

Do you restart the app in between those steps or call getGps manually somehow? Otherwise that doesn't look to wrong from what you wrote - deviceready won't fire again after turning location on I guess?

@Danbardo
Copy link
Author

Danbardo commented Aug 27, 2018

Nah, I don't leave the app. The getGps() is called every time the request times out. So every time you see the error alert, it should run the getGps() function again.

Am I wrong about that? I think it works because I see errors every 5 seconds.

Thanks for editing my post :)

@janpio
Copy link
Member

janpio commented Aug 27, 2018

Ah, I missed the getGPS() in the error handler.
Could you upload that project to Github so a developer just has to clone that instead of doing those steps manually?

@Danbardo
Copy link
Author

Sure thing,
https://github.com/Danbardo/cordova_geolocation_bug

@sulymkaa
Copy link

sulymkaa commented Dec 6, 2018

is there any update here? i have exactly the same issue in my application.

@breautek
Copy link
Contributor

I've never encountered this issue myself, but considering that we do not actually have any geolocation implementation for android (the plugin just handles declaring capabilities and permissions)... it sounds like an issue with the chrome webview.

@breautek
Copy link
Contributor

breautek commented Jun 5, 2023

Closing as stale.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants