【问题标题】:Geolocation Javascript Cordova Not Triggered地理定位 Javascript Cordova 未触发
【发布时间】:2016-06-15 19:58:08
【问题描述】:

我有一个使用 Cordova 构建的移动应用程序。 在其中一个按钮上,onclick 事件触发了一个应该提醒地理位置的功能。我已经使用来自https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/#weathercordova plugin add cordova-plugin-geolocation 为该项目安装了Cordova 地理定位API

那我就有了https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/#reference的功能

所以基本上我的 HTML 是

<button onclick="getPOS();">CLICK_ME</button>

而我的 JS 是

function getPOS(){

    alert("ok");

    var onSuccess = function(position) {
        alert('Latitude: '          + position.coords.latitude          + '\n' +
              'Longitude: '         + position.coords.longitude         + '\n' +
              'Altitude: '          + position.coords.altitude          + '\n' +
              'Accuracy: '          + position.coords.accuracy          + '\n' +
              'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
              'Heading: '           + position.coords.heading           + '\n' +
              'Speed: '             + position.coords.speed             + '\n' +
              'Timestamp: '         + position.timestamp                + '\n');
    };

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    }

    navigator.geolocation.getCurrentPosition(onSuccess, onError, { timeout: 30000 });
}

当我在我的 Firefox 浏览器中启动它时,它会询问我是否要共享位置。如果我选择分享,它会很好地显示位置。

下一步当我使用cordova构建应用程序时,当apk安装完成时,它说应用程序需要网络连接和位置.....这是正常的,这意味着一切都已正确设置。

然后我要做的是启用我的手机 GPS 和 Internet 连接

问题:在我的手机上单击链接 CLICK_ME 后,尽管启用了 GPS 和互联网,但没有任何反应。

超时后,我收到以下错误:

Code: 3 message: Timeout expired

知道这里有什么问题吗?

【问题讨论】:

    标签: javascript android html cordova


    【解决方案1】:

    将这些行添加到清单文件中

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    

    它可能缺少适用于 Android 的权限。

    问候。

    【讨论】:

    • 不,这不是问题。这两行都已经在清单文件中。
    猜你喜欢
    • 2023-03-04
    • 2015-11-28
    • 2015-11-21
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多