android–phonegap geolocation总是在超时时失败

android–phonegap geolocation总是在超时时失败,第1张

概述我在我的应用程序中使用sencha-touch2.0和phonegap2.0.0来检索用户的位置.在我的locahost上运行时,一切正常.但是,当将.apk加载到我的Android15api的设备(使用eclipse和adt插件)时,每次调用getCurrentLocation或watchPosition都不会返回…这是我的代码:geoOn:function(){

我在我的应用程序中使用sencha-touch 2.0和phonegap 2.0.0来检索用户的位置.
在我的locahost上运行时,一切正常.但是,当将.apk加载到我的Android 15 API的设备(使用eclipse和adt插件)时,每次调用getCurrentLocation或watchposition都不会返回…

这是我的代码:

geoOn: function(){    var geoReady = navigator.geolocation || undefined;    var onSuccess = function(position){            top5.app.alert('Geolocation success '+String(position.coords.latitude) + ' ' + String(position.coords.longitude),'Geolocation');            var scope = Ext.getCmp('nestedList');            scope.updatedistance(position.coords);    };    var onFailure = function(error){top5.app.alert('Geolocation Failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};    if (geoReady) {        this.watchID = navigator.geolocation.watchposition(onSuccess ,onFailure,{timeout:6000,maximumAge: 3000,enableHighAccuracy: true});        }    else{        Ext.device.Geolocation.watchposition({                 frequency: 3000, // Update every 3 seconds                 callback: function(position) {                        this.updatedistance(position.coords);                 },                 failure: function() {                   console.log('Geolocation Failure!');                 },                 scope:this        });    } }, geoGet: function(){     var geoReady = navigator.geolocation || undefined;     if (geoReady) {         var onSuccess = function(position){             top5.app.alert('Geolocation successful!!!');             var scope = Ext.getCmp('nestedList');             scope.updatedistance(position.coords);                   };         var onFailure = function(error){top5.app.alert('Geolocation Failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};         navigator.geolocation.getCurrentposition(onSuccess,onFailure);     }     else{} }, geoOff:function(){     var geoReady = navigator.geolocation || undefined;     if (geoReady) {         navigator.geolocation.clearWatch(this.watchID);         this.watchID = null;     }     else{         Ext.device.Geolocation.clearWatch();     } }, updatedistance:function(coords){     top5.app.alert('updatedist','');     var scope = Ext.getCmp('nestedList');     var lat = coords.latitude,lon = coords.longitude;     var store = scope.getStore();     var i,record;     for(i = 0; i < store.data.all.length; i++)     {         record = store.data.all[i];         if(record.data.locationX){            record.set('distance',top5.app.getdistance(record.data.locationX,record.data.locationY,lat,lon).toFixed(3));         }        }}

更新:所以我走出了我的大楼,它工作了……我需要经常出去.
但是,当我禁用gps时,我认为geolocation将使用wifi连接找到我的位置 – 但它很复杂(我设置enableHighAccuracy:false).这是为什么?

更新:让我重新解释一下我的问题:
navigator.geolocation.watchposition是否可以同时使用GPS信号和wifi / g3信号?如何仅使用互联网连接检测用户位置?目前,我的代码仅适用于GPS,当禁用该选项或信号被阻止时,地理位置无效.

解决方法:

我知道也许为时已晚,但今天我在同样的问题上挣扎了!解决方案结果非常简单!

SolUTION:重新启动设备.

就这样.

问题是,你永远不知道我的用户什么时候会遇到这种错误,所以如果你的应用程序在很大程度上依赖于地理位置,我建议你在位置选项中设置一个超时选项navigator.geolocation.getCurrentposition(geoSuccess,geoError,{timeout:15000} )并提醒用户有关问题和可能的解决方案.

附:
请记住,Geolocation可能会超时,例如,如果移动数据也被关闭,那么重启并不会始终修复它.在iPhone上,它使用手机数据来获取您的位置,但在AndroID上,看起来手机无法访问手机数据,除非3G开启

总结

以上是内存溢出为你收集整理的android – phonegap geolocation总是在超时时失败全部内容,希望文章能够帮你解决android – phonegap geolocation总是在超时时失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存