【问题标题】:cordova geolocation does not watch or get the current location instantly科尔多瓦地理定位不会立即观看或获取当前位置
【发布时间】:2016-08-04 16:44:12
【问题描述】:

我使用的是cordova 6.1.1,并且我使用的是最新版本的cordova-plugin-geolocation。我尝试了getCurrentPossition(onSuccess,onError)watchPossition(onSuccess, onError)。而且他们俩都没有立即更新我在(纬度,经度)的地理位置。

我将跟踪我的locator.jsgetTagLocation() 中的位置

getTagLocation: function(tagId,callback) {
        console.log('in getTagLocation func')
        locator.TrackingLocation();
},

跟踪位置定义为:

TrackingLocation: function() {
    var onSuccess = function(position) {
        locator.devicePosition.coords.latitude = position.coords.latitude;
        locator.devicePosition.coords.longitude = position.coords.longitude;
        locator.devicePosition.timeStamp = position.timestamp;  
    };

    var onError = function(error) {
        console.log("[ERROR]: "+error);
    };

    navigator.geolocation.watchPosition(onSuccess,onError);
},

而在我的app.js,我会显示位置:

displayResult: function(data){
        app.display("output message : ");
        app.display(data);
},

connectSuccess: function() {
    console.log("in connectSuccess");
    app.display("Connected to: " + app.macAddress);
    connectButton.innerHTML = "Disconnect";
    locator.getTagLocation('00176883',app.displayResult);
    setTimeout(function() {
        locator.unsubscribeTagLocation(app.displayResult);
    }, 30000);
},

在我看来,我所做的是将原始函数包装到我的定位器中。所以,在30s的时间段内,它应该尽快更新我的位置。但它不会在大约 5 到 6 秒左右更新我的位置,有时甚至超过 10 秒。我没有在他们的仓库中找到问题跟踪器,所以我在这里问我的问题。

【问题讨论】:

    标签: javascript cordova geolocation cordova-plugins


    【解决方案1】:

    默认设置是不好,不要使用它。

    我所做的更改是给定可选参数:

    navigator.geolocation.watchPosition(onSuccess,onError, {maximumAge: 300, timeout:1000, enableHighAccuracy: true});
    

    此更改使输出方式比默认设置更即时。

    由于这些值是硬编码的,它实际上取决于您的硬件条件。如果您希望 watchPosition 在您的设备上完美运行,我建议您对此进行一些机器学习。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      相关资源
      最近更新 更多