即使在 Android 4.4.2 中关闭了位置服务,GetCurrentLocation 仍在 Cordova/PhoneGap 应用程序上工作

Posted

技术标签:

【中文标题】即使在 Android 4.4.2 中关闭了位置服务,GetCurrentLocation 仍在 Cordova/PhoneGap 应用程序上工作【英文标题】:GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2 【发布时间】:2014-04-01 06:44:49 【问题描述】:

即使在 android 4.4.2 中关闭定位服务时,GetCurrentLocation 仍在 Cordova/PhoneGap 应用上工作。

Cordova 版本是 2.9

设备为 Nexus4 V4.4.2

代码:

var onSuccess = function() 
    alert("success")

var onError = function() 
    alert("error")

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

代码在以前的 android 版本中运行良好。 但在 Android 4.4.2 中,即使位置服务已关闭,它也会提示成功。

无法找到解决方案,我们将不胜感激。

【问题讨论】:

请更新您的 Cordova 版本 嗨,Immi,3.0 版是一个重大更新,需要大量代码更改,我没有那么多时间 您是否尝试过提醒成功坐标?如果它们未定义,只需检查它并将其视为错误。 @Regent 他们不是未定义的 它们显示正确的值吗?如果是这样,也许您应该在更改定位服务设置后重新启动手机 【参考方案1】:

在 Cordova V2.9 中有一个与此处提到的当前位置相关的错误:GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2

由于 Cordova 使用默认浏览器的 Geolocation 实现,这是这里提到的 WebView 错误:https://issues.apache.org/jira/browse/CB-6548

作为一种解决方法,此插件使用 Android API 检查定位服务的状态。

插件:https://github.com/mandeeppasbola/Cordova-Plugins/tree/master/Location%20Service%20Status

【讨论】:

以上是关于即使在 Android 4.4.2 中关闭了位置服务,GetCurrentLocation 仍在 Cordova/PhoneGap 应用程序上工作的主要内容,如果未能解决你的问题,请参考以下文章

如何在android中知道用户是否关闭了位置[重复]

SonarLint 提示“关闭这个'FileReader'”,当我关闭时实际上在finally块中关闭了它

如何在 Xamarin.Forms 中创建永无止境的后台服务?

即使用户在android studio中关闭应用程序,如何保持登录状态

当我在谷歌设置android中关闭和打开位置时,FusedLocation 不起作用

在 Titanium Android 中关闭移动数据时,一次拍摄 getCurrentLocation 无法获取新位置