Commit 2b2fe8ae authored by Damon's avatar Damon

定位信息缓存

parent 31ccb757
......@@ -45,7 +45,8 @@
// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG",
ak: "lF1HoyXdiv4uZx6TrGQEZs48F5y8kEHI"
});
import standard from '@/components/photo/standard.vue'
import standard from '@/components/photo/standard.vue'
import cache from '../../common/cache.js'
export default {
components: {
'photo-standard': standard,
......@@ -95,7 +96,17 @@
getApp().trackPage('拍照页')
// this.ctx = uni.createCameraContext();
this.updateTime()
this.getLocation()
const locationData = cache.getCache('locationData')
const validityTime = 60000
if (Date.now() - locationData.locationTime < validityTime) { // 1分钟内不重复请求位置信息
this.waterInfo.latitude = locationData.waterInfo.latitude
this.waterInfo.longitude = locationData.waterInfo.longitude
this.baiduLocation()
} else {
this.getLocation()
}
this.getMarkPath()
this.initData()
......@@ -256,8 +267,16 @@
type: 'gcj02',
success: function(res) {
waterInfo.longitude = parseFloat(res.longitude).toFixed(4)
waterInfo.latitude = parseFloat(res.latitude).toFixed(3)
// console.log(waterInfo.longitude, 'that.longitude', waterInfo.latitude, 'that.latitude')
waterInfo.latitude = parseFloat(res.latitude).toFixed(3)
const data = {
waterInfo: {
latitude: waterInfo.latitude,
longitude: waterInfo.longitude
},
locationTime: Date.now()
}
cache.setCache('locationData', data)
that.baiduLocation()
},
fail(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment