定时任务 每30s执行一次
setInterval(() => {
console.log('----------');
this.getLocationMethod();
}, 30000);
实时获取当前位置
getLocationMethod(){
var that = this;
uni.getLocation({//获取当前的位置坐标
type: 'wgs84',
geocode: true,
success: function (res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
that.longitude = res.longitude;
that.latitude = res.latitude;
var params = {
"userX": that.longitude,
"userY": that.latitude
};
service.saveUserXy(params).then(res => {
console.log("当前位置上传成功!")
});
},
fail: function () {
console.log('获取当前定位失败');
}
});
},