phonegap geolocation, Code 3 - timeout expired keeps popping up on some Android Devices

我的未来我决定 提交于 2019-12-23 09:04:23

问题


I am using the PhoneGap API for geolocation. I have set the enableHighAccuracy Option to "true". Code 3, time out expired option keeps popping up, but only on some android devices and more than once while using the application.

Please help me... Why is this so that it fails only on some android devices. If I set the accuracy to false, how much difference will I get in retrieving the coordinates...


回答1:


Managed to resolve my issue with the code below:

var options = {maximumAge: 0, timeout: 10000, enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

It seems that samsung galaxy phones do not like to cache the gps location.




回答2:


Ok, here how to fix the issue:

  1. Add a timeout and set enableHighAccuracy:

    navigator.geolocation.getCurrentPosition(onSuccess, onError, {timeout: 10000, enableHighAccuracy: true});
    

    In certain emulators you need to set enableHighAccuracy to false, so try that if still doesn't work.

  2. In Android, the emulator don’t read GPS values, so we need to send them via command line. We need to start a telnet session in the port that the emulator is running (you can check the port in the emulator window title, the number at the beginning, in my case 5554):

    telnet localhost 5554
    

And then run the command

    geo fix -122.4 37.78

If you close the app you need to re-send the geolocation, so if it doesn’t work, just run the geo fix command just after opening the app, before the timeout event fires.




回答3:


I've faced the same error on Samsung Galaxy Note II (Android 4.1.1). For some reason, when 'Use wireless networks' under the Location settings is on it works, but if it's off it gets the code 3 error. It didn't happen on Nexus 7 (4.2.2).




回答4:


Ouch, found same problem here. Wish there were a better way around it than asking users to kindly change their GPS settings. Samsung Galaxy III

(works when "use wireless networks to find position" fails without this option)



来源:https://stackoverflow.com/questions/16262878/phonegap-geolocation-code-3-timeout-expired-keeps-popping-up-on-some-android

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