【问题标题】:Nativescript timed service or thread for geolocation tracking用于地理定位跟踪的 Nativescript 定时服务或线程
【发布时间】:2016-06-22 07:21:47
【问题描述】:

我需要创建循环线程或定时服务来获取纬度和经度,尤其是在它发生变化时。我应该怎么做。我目前正在使用 nativescript-geolocation 插件 (https://www.npmjs.com/package/nativescript-geolocation)。

【问题讨论】:

    标签: multithreading service geolocation nativescript


    【解决方案1】:

    当您在线程中关注link 时,您将在 github 上看到整个示例代码。

    您可以通过以下方式获取当前位置:

    var location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000}).
    then(function(loc) {
        if (loc) {
             // Your code here
        }
    }, function(e){
        console.log("Error: " + e.message);
    });
    

    当你想继续更新它时,你可以使用:

    var watchId = geolocation.watchLocation(
    function (loc) {
        if (loc) {
            // Your code here
        }
    }, 
    function(e){
        console.log("Error: " + e.message);
    }, 
    {desiredAccuracy: 3, updateDistance: 10, updateTime: 1000 * 20}); // should update every 20 sec according to google documentation this is not so sure.
    

    【讨论】:

    • 非常感谢,这正是我想要的!
    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多