phonegap geolocation always fail on timeout

北战南征 提交于 2019-11-27 22:07:31

I know that maybe it is too late, but today i struggled with the same issue! The solution turned out to be very simple!

SOLUTION: Reboot the device.

That's all.

The problem is, that you never know when i user will get this kind of bug, so if your application relies heavily on geolocation i recommend you set a timeout in location options navigator.geolocation.getCurrentPosition(geoSuccess, geoError, {timeout: 15000}) and alert user about the problem and possible solution.

P.S. Keep in mind, that Geolocation can timeout for example if mobile data is turned off too, so reboot won't always fix it. On iPhone it uses cellular data to get your position, but on Android, it looks like the phone does not have access to cellular data unless 3G is turned on

It could sound stupid, but, did you activate the "Use Networks" option?

Go to Settings -> Location and security -> Use networks; and active it. I have passed all the afternoon watching the problem and it was that.

Alain Zelink

I restarted and restarted. I reset my phone to factory settings.

But nothing worked.

Until I set enablHighAccuracy from true to false.

And... Tada.... it works.

So :

var options;

options = {
    maximumAge: 30000,
    timeout: 5000,
    enableHighAccuracy: false
};

This used to work fine using PhoneGap 2.6.0. I needed to make this change since I'm now using Phonegap 3.3 - tested on a Wiko Cink+ phone.

If you are running on an emulator, it may be because the device does not have a geolocation set. Try setting the location by running the following, assuming your android emulator is on port 5554:

telnet localhost 5554
geo fix -0.001 51.5

Try removing the Phonegap plugin geolocation plugin from your project. You won't need to make any changes to your JavaScript code as your device will fall back on the standard HTML5 navigator.geolocation functionality which has the same method signature.

Assuming you're using PhoneGap 3.3, you just need to run:

cordova plugin rm org.apache.cordova.geolocation

Restart your phone or Go to google map and check if gps is working over there. I got it working.

I had this happen to a working app after updating PhoneGap to version 3.6.3 from 3.5. After trying many other suggestions Arthur's answer worked. 15 seconds seemed too long to me so I used {timeout: 2000}. I'm guessing the new version is slower as my code worked fine before the update on the same devices. Thought I'd post as well as upvote him as everything I found in Google was about initial setup and mostly irrelevant to my situation.

Roman Galochkin

You just need to add enableHighAccuracy: true, maximumAge: 60000 and then reboot your device.

From my trial and error analysis, its most likely: 1. The version of android you're using. On Lollipop and lower you may need to go to the phones location settings and enable high accuracy settings (using gps, wlan and mobile networks to get location). I had to do this on a kitkat phone. 2. As others have mentioned, you can try changing the settings of getCurrentPosition by either enabling/disabling highaccuracy and adding a timeout. 3.If you're using ngCordova, make sure you installed it right and the location functions are actually being called. Use console to verify

Try This Solution:

window.setInterval(checkPosition, 5000);

function checkPosition() {
 function onSuccess(position) {
    document.getElementById('result1').innerHTML = position.coords.latitude;
    document.getElementById('result2').innerHTML = position.coords.longitude;
 }

 // onError Callback receives a PositionError object
 //
 function onError(error) {
    alert('code: '    + error.code    + '\n' +
        'message: ' + error.message + '\n');
 }
 navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

I've managed to work it out.... However , I have no idea what actually solved it. All I've done is to change one of my model's structure. Can anyone see the connection to geolocation?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!