[英]If location services is turned off, CLLocationManager never updates
[英]Phonegap build “deviceready” event never fires if the location service is turned off
我已经使用JQM(1.3.1),jQuery(1.9),CSS3和javascript编写了一个Webapp,现在我处于第二阶段,我正在使用手机差距(2.7)(目标iOS(6.1)/ iPhone5-问题可以在iPhone 4S / iOS 6.0上重现
当在浏览器中执行时,如下所示的地理位置代码可以正常工作。
var geoOptions = { 'enableHighAccuracy': true, 'timeout': 10000, 'maximumAge': 0 };
navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOptions);
function geoSuccess(postion)
{
//on success code here
}
function geoError(error)
{
//on error code here
}
但是,一旦通过phonegap,我的应用就会请求用户两次访问位置服务的权限,即显示两次弹出窗口。 因此,为了解决这一问题,我使用了许多关于stackoverflow的解决方案中所建议的以下代码。
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError,geoOptions);
}
$(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});
这解决了弹出问题,但是开始了新的问题。
问题:如果禁用了位置服务,我的代码将添加deviceready侦听器并等待deviceready事件触发,但是该事件从不触发,它就坐在那儿。 如果打开了定位服务,它将按预期工作。
有没有人遇到过这个问题,在您能提出建议之前,我是否可以解决这个问题,请问我已经花了一天的时间进行调试和研究。
亲切的问候,谢谢。
问题解决了! :)
事实证明,我并没有完全按照phonegap构建文章中的描述包括电话空白库。
检查本文https://build.phonegap.com/docs/preparing-your-app
您无需在每个页面上都包括此库,而只需在索引页面上就可以了,我不确定它有什么区别,但是在删除了其他任何页面上对phonegap.js的引用之后,“ deviceready”事件就开始触发,但是index.html的。
我注意到的第二件事是由于某种原因,在构建phonegap之后,如下所示的错误处理停止了工作。
switch(error.code)
{
case error.PERMISSION_DENIED:
search.openPanelForSearch("Either the app was denied permission or the location srvice is currently turned off.", showInitialMap);
break;
case error.POSITION_UNAVAILABLE:
search.openPanelForSearch("Geolocation information was unavailable. Would you like to try out a manual serach instead?", showInitialMap);
break;
case error.TIMEOUT:
search.openPanelForSearch("Service was timed out since it took too long to retrieve the gelolcations. Would you like to try out a manual search instead?", showInitialMap);
break;
case error.UNKNOWN_ERROR:
search.openPanelForSearch("Sorry an unknown error occurred. Would you like to try out a manual serach instead?", showInitialMap);
break;
}
我必须将其更改为以下
switch(error.code)
{
case 1:
search.openPanelForSearch("Either the app was denied permission or the location service is currently turned off.", showInitialMap);
break;
case 2:
search.openPanelForSearch("Geolocation information was unavailable. Would you like to try out a manual search instead?", showInitialMap);
break;
case 3:
search.openPanelForSearch("Service was timed out since it took too long to retrieve the gelolcations. Would you like to try out a manual serach instead?", showInitialMap);
break;
default:
search.openPanelForSearch("Sorry an unknown error occurred. Would you like to try out a manual search instead?", showInitialMap);
break;
}
希望这对某人有帮助。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.