简体   繁体   English

仅限Android 4.0设备上的Phonegap getCurrentPosition超时

[英]Phonegap getCurrentPosition timeout on Android 4.0 devices only

I have developed an app which is now live on Google Play store. 我开发了一款现已在Google Play商店上线的应用。 The app uses the getCurrentPosition method to get the current location of a user. 该应用程序使用getCurrentPosition方法获取用户的当前位置。

I have tested on a few devices, and the code works perfectly. 我已经在一些设备上进行了测试,代码运行良好。 Those devices being the Nexus 4, Nexus 5, Samsung Galaxy S3 and S4. 这些设备是Nexus 4,Nexus 5,三星Galaxy S3和S4。 Perfect. 完善。

I have now found issues with the app on Android devices lower than 4.1 (namely 4.0.4, which seems the most used version other than those mentioned). 我现在发现Android设备上的应用程序问题低于4.1(即4.0.4,这似乎是除了上面提到的最常用的版本)。

The app constantly returns a timeout error. 该应用程序不断返回超时错误。 I know location services are switched on on the device. 我知道位置服务已在设备上打开。

I have amended the options for getCurrentPosition and included a maximumAge , timeout and enableHighAccuracy . 我修改了getCurrentPosition的选项,包括maximumAgetimeoutenableHighAccuracy I have tried all sorts of options; 我尝试了各种各样的选择; from reasonable timeouts/ages, low timeouts/ages to high timeouts/ages. 从合理的超时/年龄,低超时/年龄到高超时/年龄。 I have tried turning enableHighAccuracy on ( true ) and off ( false ) in all permutations. 我试过在所有排列中打开( true )和关闭( false )的enableHighAccuracy The timeout is being taken into account (eg. the error callback isn't being hit until timeout is reached). 正在考虑超时(例如,在达到超时之前没有命中错误回调)。

There are a few similar threads on StackOverflow, but none match my problem. StackOverflow上有一些类似的线程,但没有一个符合我的问题。 I have tried turning the device off, deleting and re-adding the app, and recompiled it several times. 我尝试关闭设备,删除并重新添加应用程序,并重新编译了几次。 Same issue. 同样的问题。

The device being tested is a HTC Sensation, but I have also tried on a HTC Wildfire, and there are similar bug reports coming from users out in the wild - all the same. 正在测试的设备是HTC Sensation,但我也尝试过HTC Wildfire,并且有类似的bug报告来自用户外面 - 都是一样的。

Below is sample code, but like I say, I've tried all sorts of options (higher age than timeout, higher timeout than age, high accuracy on and off in both cases, etc). 下面是示例代码,但就像我说的,我已经尝试了各种选项(超过超时,超过年龄的超时,两种情况下的高精度开启和关闭等)。

if (navigator.geolocation) navigator.geolocation.getCurrentPosition(function(pos) {
        console.log('Working...');
    }, function(error, msg) {
        console.log(error.code + ' - '+ error.message);
    },
    { maximumAge: 90000, timeout: 9000, enableHighAccuracy: false });

LogCat spits out: 3 - Position retrieval timed out. at file:///[...] LogCat吐出: 3 - Position retrieval timed out. at file:///[...] 3 - Position retrieval timed out. at file:///[...]

Update : Changing to watchPosition has no effect, the device will not find the location still. 更新 :更改为watchPosition无效,设备仍无法找到该位置。

This was a problem with the device rather than a problem with Android (possibly) or Phonegap (certainly). 这是设备的问题,而不是Android(可能)或Phonegap(当然)的问题。 Location based services were not working on the default Android Browser, or anything that uses the native browser (Maps app DOES work). 基于位置的服务无法在默认的Android浏览器上运行,也无法使用本机浏览器(地图应用程序可以正常工作)。

I fixed this on the device by turning off location services, rebooting the device and restarting all location services, forcing re-acceptance of terms/certificates/etc. 我通过关闭位置服务,重新启动设备并重新启动所有位置服务,强制重新接受条款/证书等来在设备上修复此问题。 Location services then sprung into life, browser found where I was and the app worked as it should. 定位服务随后涌入生活,浏览器找到了我的位置,应用程序正常工作。

Found a few people complaining of this online, and I've experienced it on more than one device running the same Android version. 发现有几个人在网上抱怨这个,我在不止一个运行相同Android版本的设备上体验过它。

For me, the geolocation plugin had not successfully installed for some reason. 对我来说,geolocation插件由于某种原因没有成功安装。 Run cordova plugins list to make sure that cordova-plugin-geolocation is there. 运行cordova plugins list以确保cordova-plugin-geolocation存在。 If not, run cordova plugins add cordova-plugin-geolocation . 如果没有,运行cordova plugins add cordova-plugin-geolocation Sometimes removing and re-adding a plugin or entire platform will fix errors as well. 有时删除和重新添加插件或整个平台也会修复错误。

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

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