简体   繁体   English

phonegap地理定位,代码3 - 超时过期一直在某些Android设备上弹出

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

I am using the PhoneGap API for geolocation. 我正在使用PhoneGap API进行地理定位。 I have set the enableHighAccuracy Option to "true". 我已将enableHighAccuracy选项设置为“true”。 Code 3, time out expired option keeps popping up, but only on some android devices and more than once while using the application. 代码3,超时过期选项不断弹出,但仅在某些Android设备上使用该应用程序时不止一次。

Please help me... Why is this so that it fails only on some android devices. 请帮助我...为什么这只是在一些Android设备上失败。 If I set the accuracy to false, how much difference will I get in retrieving the coordinates... 如果我将精度设置为false,我将在检索坐标时获得多少差异...

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. 似乎三星Galaxy手机不喜欢缓存gps的位置。

Ok, here how to fix the issue: 好的,这里有如何解决问题:

  1. Add a timeout and set enableHighAccuracy: 添加超时并设置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. 在某些模拟器中,您需要将enableHighAccuracy设置为false,因此如果仍然不起作用请尝试。

  2. In Android, the emulator don't read GPS values, so we need to send them via command line. 在Android中,模拟器不读取GPS值,因此我们需要通过命令行发送它们。 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会话(您可以检查模拟器窗口标题中的端口,开头的数字,在我的情况下为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. 如果您关闭应用程序,则需要重新发送地理位置,因此如果它不起作用,只需在打开应用程序之后,在超时事件触发之前运行geo fix命令。

I've faced the same error on Samsung Galaxy Note II (Android 4.1.1). 我在三星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. 出于某种原因,当位置设置下的“使用无线网络”打开时,它可以正常工作,但如果它关闭则会出现代码3错误。 It didn't happen on Nexus 7 (4.2.2). 它没有发生在Nexus 7(4.2.2)上。

Ouch, found same problem here. 哎哟,在这里发现同样的问题。 Wish there were a better way around it than asking users to kindly change their GPS settings. 希望有一个更好的方法,比要求用户友好地改变他们的GPS设置。 Samsung Galaxy III 三星Galaxy III

(works when "use wireless networks to find position" fails without this option) (在没有此选项的情况下“使用无线网络查找位置”失败时工作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM