Commit 2b2fe8ae authored by Damon's avatar Damon

定位信息缓存

parent 31ccb757
...@@ -45,7 +45,8 @@ ...@@ -45,7 +45,8 @@
// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG", // ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG",
ak: "lF1HoyXdiv4uZx6TrGQEZs48F5y8kEHI" ak: "lF1HoyXdiv4uZx6TrGQEZs48F5y8kEHI"
}); });
import standard from '@/components/photo/standard.vue' import standard from '@/components/photo/standard.vue'
import cache from '../../common/cache.js'
export default { export default {
components: { components: {
'photo-standard': standard, 'photo-standard': standard,
...@@ -95,7 +96,17 @@ ...@@ -95,7 +96,17 @@
getApp().trackPage('拍照页') getApp().trackPage('拍照页')
// this.ctx = uni.createCameraContext(); // this.ctx = uni.createCameraContext();
this.updateTime() 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.getMarkPath()
this.initData() this.initData()
...@@ -256,8 +267,16 @@ ...@@ -256,8 +267,16 @@
type: 'gcj02', type: 'gcj02',
success: function(res) { success: function(res) {
waterInfo.longitude = parseFloat(res.longitude).toFixed(4) waterInfo.longitude = parseFloat(res.longitude).toFixed(4)
waterInfo.latitude = parseFloat(res.latitude).toFixed(3) waterInfo.latitude = parseFloat(res.latitude).toFixed(3)
// console.log(waterInfo.longitude, 'that.longitude', waterInfo.latitude, 'that.latitude')
const data = {
waterInfo: {
latitude: waterInfo.latitude,
longitude: waterInfo.longitude
},
locationTime: Date.now()
}
cache.setCache('locationData', data)
that.baiduLocation() that.baiduLocation()
}, },
fail(err) { 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