开发者社区> 问答> 正文

dd.device.geolocation.get获取当前位置相关 Android上定位不实时更新

我用dd.device.geolocation.get获取当前位置,但是发现 [font='Microsoft Yahei', 微软雅黑, Arial]Android定位取到的不是实时的信息 [font='Microsoft Yahei', 微软雅黑, Arial](刷新定位IOS是定位是会更新)。这个问题有办法解决吗?




//每60秒刷新一次
        setInterval(function () {
            DoGeolocation();
        }, 60000);


var geolInfo = [];//地理信息



//获取地理位置信息function GetGeolocation() {
    dd.ready(function () {        dd.device.geolocation.get({
            targetAccuracy: 200,            coordinate: 1,
            withReGeocode: true,            onSuccess: function (data) {
                geolInfo = data;                if (geolInfo.latitude != undefined && geolInfo.latitude != null && geolInfo.latitude != '' &&
                    geolInfo.longitude != undefined && geolInfo.longitude != null && geolInfo.longitude != '' &&                    geolInfo.address != undefined && geolInfo.address != null && geolInfo.address != '') {
                    $("#currentAddress").text(geolInfo.address);                    var workPlaceIPConfig = $("#workPlaceIPConfig").val();
                    if (workPlaceIPConfig != null && workPlaceIPConfig != '') {                        var config = workPlaceIPConfig.split('|');
                        var minDisance = 0;                        var baseAccuracy = 0;
                        for (var i = 0; i < config.length; i++) {                            var coo = config .split('^');
                            var disance = getDisance(parseFloat(coo[1]), parseFloat(coo[2]), parseFloat(geolInfo.latitude), parseFloat(geolInfo.longitude));                            if (minDisance == 0 || disance < minDisance) {
                                minDisance = disance;                                baseAccuracy = parseFloat(coo[3]);
                            }                        }
                        var spacing = baseAccuracy - minDisance;                        spacing = Math.abs(spacing.toFixed(2));
                        var punchDataId = $("#punchDataId").val();                        if (minDisance < baseAccuracy) {
                            $('.Sbtn-tip').hide();                            $('#refreshPunch').hide();//刷新
                            if (punchDataId == "0") {                                $('#GTWPunch').show();
                                $('#GOWPunch').hide();                            }
                            else {                                $('#GOWPunch').show();
                                $('#GTWPunch').hide();                            }
                        }                        else {
                            $('.Sbtn-blue').hide();                            $('.Sbtn-org').show();
                            $('.Sbtn-tip').show();                        }
                    }                    else {
                        $('.Sbtn-blue').hide();                        $('.Sbtn-org').show();
                        $('.Sbtn-tip').show();                    }
                }                else {
                    $.toast('获取地理位置信息失败,请检查手机网络已经连接上 ', 2000, 'success top');                    $('.Sbtn-blue').hide();
                    $('.Sbtn-org').show();                    $('.Sbtn-tip').hide();
                }            },
            onFail: function (err) {                $.toast('获取地理位置信息失败', 2000, 'success top');
                $('.Sbtn-blue').hide();                $('.Sbtn-org').show();
                $('.Sbtn-tip').hide();            }
        });    });
}


展开
收起
火山桑 2017-08-14 16:01:45 4288 0
1 条回答
写回答
取消 提交回答
  • Redd.device.geolocation.get获取当前位置相关 Android上定位不实时更新
    安卓手机上我把钉钉退出重登 定位才会改变
    2017-08-14 16:10:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载