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

Geolocation getcurrent position passing 0 (Time out error) #233

Closed
Rmadhuprasanth opened this issue Sep 7, 2021 · 5 comments
Closed

Geolocation getcurrent position passing 0 (Time out error) #233

Rmadhuprasanth opened this issue Sep 7, 2021 · 5 comments

Comments

@Rmadhuprasanth
Copy link

Rmadhuprasanth commented Sep 7, 2021

ISSUE:I have been using cordova-plugin-geolocation in my project but some times even if internet & Geolocation enabled the getCurrentposition passing lat&long 0 values in Android

Plugin version: "cordova-plugin-geolocation": "^4.0.1"
Error code:"Location error code: 3
message: Timeout expired"
Any quick Possible solution could be helpful
Thanks in Advance

@breautek

getCurrentLocation = function getLocation() {
		return new Promise(function (resolve, reject) {
			$geolocation.get().then(
				function (position) {
					resolve(position)
				},
				function (error) {
					if (util.isNativeApp()) {
						navigator.geolocation.getCurrentPosition(
							function (position) {
								console.log('location success');
								resolve(position);
							},
							function (error) {
						resolve();
							}, {
								enableHighAccuracy: true,
								timeout: 30000,  // 0.5 minutes
								maximumAge: 15000
							});
						return;
					}
					resolve()

				});

		});
	}
@breautek
Copy link
Contributor

A timeout errors means there isn't an acceptable GPS point available within the timeout period.

In my experience, this mostly happens when requesting for high accuracy positioning and the device location settings is set to GPS/Device only. When location mode is set to GPS only, it can take upwards of ~15 minutes before GPS information is available.

@Rmadhuprasanth
Copy link
Author

@breautek Thanks for the reply
FYI We dint set location settings GPS alone
am i missing anything Please let me know.
Thanks

@jfoclpf
Copy link

jfoclpf commented Dec 7, 2021

I had the same error on a Xiaomi MIUI Android 11 device, and in my case strangely although you explicitly give location permission to the app, you still have to enforce that permission in Android Settings -> Location -> Toggle Location access. That is, the error in this case was PositionError.TIMEOUT and not PositionError.PERMISSION_DENIED

But thanks anyway for the tip @breautek cause it led me to the solution

@oesah
Copy link

oesah commented May 5, 2022

In my case it was also an issue with the GPS completely disabled in the phone. Thanks to @jfoclpf for this.

It would be amazing, if this plugin could detect if the GPD is completely disabled in the settings to we can actually notify the user about this. Is that already possible?

@breautek
Copy link
Contributor

breautek commented May 5, 2022

It would be amazing, if this plugin could detect if the GPD is completely disabled in the settings to we can actually notify the user about this. Is that already possible?

Apache generally follows the W3C spec whenever possible or when it exists, and I don't believe that is part of the spec, so I don't think that would gain support. However, there is an existing third-party plugin available that does just that, take a look at the diagnostics. Just ensure you specify the modules that you need to avoid adding unneeded permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants