| | |
| | | this.getOnceSPosition = null; |
| | | this.state = false; |
| | | this.isContinued = false; |
| | | this.isContinuedTime = null; |
| | | this.isContinuedTimeInt = null; |
| | | this.isContinuedTimeOut = null; |
| | | return this; |
| | | } |
| | | //开始获取 |
| | |
| | | console.log("开始持续定位") |
| | | let that = this; |
| | | this.isContinued = true; |
| | | if (this.isContinuedTime) { |
| | | if (this.isContinuedTimeInt) { |
| | | console.log("重复开始持续定位") |
| | | return; |
| | | } else { |
| | |
| | | console.log(res.intlat) |
| | | } |
| | | }) |
| | | this.isContinuedTime = setInterval(() => { |
| | | this.isContinuedTimeInt = setInterval(() => { |
| | | that.once(function(res) { |
| | | if (res.state == false) { |
| | | console.log(res.intlat) |
| | |
| | | }, 5000) |
| | | } |
| | | } |
| | | continuedTime(val) { |
| | | //开始持续获取定位 |
| | | let that = this; |
| | | if (val != 1) { |
| | | console.log("开始持续定位") |
| | | this.isContinued = true; |
| | | that.once(function(res) { |
| | | if (res.state == false) { |
| | | // console.log(res.intlat) |
| | | that.outData(); |
| | | } |
| | | }) |
| | | if (this.isContinuedTimeOut) { |
| | | console.log("重复开始持续定位") |
| | | return; |
| | | } |
| | | } |
| | | this.isContinuedTimeOut = setTimeout(() => { |
| | | that.once(function(res) { |
| | | if (res.state == false) { |
| | | // console.log(res.intlat) |
| | | that.outData(); |
| | | if (res.ok) { |
| | | //返回成功 |
| | | that.continuedTime(1); |
| | | } else { |
| | | //返回失败 |
| | | that.continuedTime(1); |
| | | } |
| | | } |
| | | }) |
| | | }, 5000) |
| | | |
| | | } |
| | | overContinued() { |
| | | console.log("结束持续定位") |
| | | let that = this; |
| | | if (this.isContinued) { |
| | | this.isContinued = false; |
| | | clearInterval(that.isContinuedTime); |
| | | this.isContinuedTime = null; |
| | | if (this.isContinuedTimeInt) { |
| | | clearInterval(that.isContinuedTimeInt); |
| | | this.isContinuedTimeInt = null; |
| | | } |
| | | if (this.isContinuedTimeOut) { |
| | | clearTimeout(that.isContinuedTimeOut); |
| | | this.isContinuedTimeOut = null; |
| | | } |
| | | } |
| | | } |
| | | // overContinued() { |
| | | // console.log("结束持续定位") |
| | | // let that = this; |
| | | // if (this.isContinued) { |
| | | // this.isContinued = false; |
| | | // clearInterval(that.isContinuedTimeInt); |
| | | // this.isContinuedTimeInt = null; |
| | | // } |
| | | // } |
| | | once(fn) { |
| | | console.log("开始获取一次定位"); |
| | | this.state = true; |
| | | let that = this,fns = '', |
| | | let ok = true; |
| | | let that = this, |
| | | fns = fn, |
| | | outit = function() { |
| | | if (fns) { |
| | | fns({ |
| | | state: that.state, |
| | | intlat: that.onceNowPosition |
| | | intlat: that.onceNowPosition, |
| | | ok: ok |
| | | }) |
| | | } else { |
| | | that.outData(); |
| | |
| | | // console.log(lon, lat, "成功"); |
| | | that.onceNowPosition = [lat, lon]; |
| | | that.state = false; |
| | | ok = true; |
| | | outit(); |
| | | }; |
| | | let error = function(error) { |
| | |
| | | } |
| | | that.onceNowPosition = msg; |
| | | that.state = false; |
| | | ok = true; |
| | | outit(); |
| | | }; |
| | | let options = { |