| | |
| | | |
| | | class $getPositions { |
| | | constructor(arg) { |
| | | this.id = arg.id || 0; //任务id |
| | | this.fn = arg.fn ? function(data) { |
| | | this.fn = arg.fn ? function (data) { |
| | | arg.fn(data); |
| | | } : function(data) { |
| | | } : function (data) { |
| | | console.log("未设置输出回调") |
| | | return data; |
| | | }; |
| | |
| | | this.isContinued = false; |
| | | this.isContinuedTimeInt = null; |
| | | this.isContinuedTimeOut = null; |
| | | this.geolocation = null; //定位实例 |
| | | return this; |
| | | } |
| | | //开始获取 |
| | |
| | | console.log("重复开始持续定位") |
| | | return; |
| | | } else { |
| | | that.once(function(res) { |
| | | that.once(function (res) { |
| | | if (res.state == false) { |
| | | console.log(res.intlat) |
| | | } |
| | | }) |
| | | this.isContinuedTimeInt = setInterval(() => { |
| | | that.once(function(res) { |
| | | that.once(function (res) { |
| | | if (res.state == false) { |
| | | console.log(res.intlat) |
| | | } |
| | |
| | | continuedTime(val) { |
| | | //开始持续获取定位 |
| | | let that = this; |
| | | that.geolocation = new qq.maps.Geolocation("T7RBZ-62U3X-RSQ4P-ZZVCB-WE7JT-HRBOG", "mapqq"); |
| | | if (val != 1) { |
| | | // console.log(that.id,"开始持续定位") |
| | | this.isContinued = true; |
| | | that.once(function(res) { |
| | | that.once(function (res) { |
| | | if (res.state == false) { |
| | | // console.log(res.intlat) |
| | | that.outData(); |
| | |
| | | } |
| | | } |
| | | this.isContinuedTimeOut = setTimeout(() => { |
| | | that.once(function(res) { |
| | | that.once(function (res) { |
| | | if (res.state == false) { |
| | | // console.log(res.intlat) |
| | | that.outData(); |
| | |
| | | } |
| | | } |
| | | }) |
| | | }, 30000) |
| | | }, 3000) |
| | | |
| | | } |
| | | overContinued() { |
| | |
| | | clearTimeout(that.isContinuedTimeOut); |
| | | this.isContinuedTimeOut = null; |
| | | } |
| | | if (this.geolocation) { |
| | | this.geolocation = null; |
| | | } |
| | | } |
| | | this.isContinued = false; |
| | | that.outData('out'); |
| | |
| | | let ok = true; |
| | | let that = this, |
| | | fns = fn || '', |
| | | outit = function() { |
| | | outit = function () { |
| | | if (fns) { |
| | | fns({ |
| | | state: that.state, |
| | |
| | | } |
| | | }; |
| | | outit(); |
| | | // uni定位 |
| | | console.log(uni.getLocation) |
| | | //qq定位 |
| | | var geolocation = new qq.maps.Geolocation("T7RBZ-62U3X-RSQ4P-ZZVCB-WE7JT-HRBOG", "mapqq"); |
| | | var options = { |
| | | // timeout: 1000 |
| | | }; |
| | | // var geolocation = new qq.maps.Geolocation("T7RBZ-62U3X-RSQ4P-ZZVCB-WE7JT-HRBOG", "mapqq"); |
| | | // console.log(that.geolocation) |
| | | // var options = { |
| | | // // timeout: 1000 |
| | | // }; |
| | | |
| | | function showPosition(position) { |
| | | let lat = position.lat; // |
| | | let lng = position.lng; //火星坐标 //TODO 实现业务代码逻辑 |
| | | that.onceNowPosition = [lng, lat]; |
| | | // console.log(that.onceNowPosition) |
| | | that.state = false; |
| | | ok = true; |
| | | outit(); |
| | | } |
| | | // function showPosition(position) { |
| | | // console.log("position:", position) |
| | | // console.log("position:", JSON.stringify(position)) |
| | | // let lat = position.lat; // |
| | | // let lng = position.lng; //火星坐标 //TODO 实现业务代码逻辑 |
| | | // that.onceNowPosition = [lng, lat]; |
| | | // // console.log(that.onceNowPosition) |
| | | // that.state = false; |
| | | // ok = true; |
| | | // outit(); |
| | | // } |
| | | |
| | | function showErr(data) { |
| | | console.log(data) |
| | | that.onceNowPosition = data; |
| | | that.state = false; |
| | | ok = true; |
| | | outit(); |
| | | }; |
| | | geolocation.getLocation(showPosition, showErr, options); |
| | | // function showErr(data) { |
| | | // console.log(data) |
| | | // that.onceNowPosition = data; |
| | | // that.state = false; |
| | | // ok = true; |
| | | // outit(); |
| | | // }; |
| | | // that.geolocation.getLocation(showPosition, showErr, options); |
| | | // 高德定位 |
| | | // console.log(AMap) |
| | | // AMap.plugin("AMap.Geolocation", function() { |
| | |
| | | } |
| | | } |
| | | |
| | | // export default $getPositions; |
| | | // export default $getPositions; |