|
|
@ -27,37 +27,20 @@ const instance = defineStore('user', { |
|
|
|
|
|
|
|
|
|
|
|
actions: { |
|
|
|
actions: { |
|
|
|
getPosition() { |
|
|
|
getPosition() { |
|
|
|
this.position = { latitude: 36.636753, longitude: 119.11914 } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (navigator?.geolocation?.getCurrentPosition) { |
|
|
|
|
|
|
|
console.log('存在原生定位') |
|
|
|
|
|
|
|
navigator.geolocation.getCurrentPosition(position => { |
|
|
|
|
|
|
|
console.log('原生定位', position) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.log('原生定位不可用') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
initAMap().then(() => { |
|
|
|
initAMap().then(() => { |
|
|
|
// console.log(3)
|
|
|
|
|
|
|
|
let AMap = Vue.prototype.$AMap |
|
|
|
let AMap = Vue.prototype.$AMap |
|
|
|
let geolocation = new AMap.Geolocation({ |
|
|
|
let geolocation = new AMap.Geolocation({ |
|
|
|
// enableHighAccuracy: true // 是否使用高精度定位,默认:true
|
|
|
|
// enableHighAccuracy: true // 是否使用高精度定位,默认:true
|
|
|
|
}) |
|
|
|
}) |
|
|
|
geolocation.getCurrentPosition(function (status, result) { |
|
|
|
geolocation.getCurrentPosition(function (status, result) { |
|
|
|
console.log('geolocation.getCurrentPosition') |
|
|
|
if (status === 'complete') { |
|
|
|
console.log('status', status) |
|
|
|
let { lat: latitude, lng: longitude } = result.position |
|
|
|
console.log('result', result) |
|
|
|
this.position = { latitude, longitude } |
|
|
|
// if (status === 'complete') {
|
|
|
|
} else { |
|
|
|
// let { lat: latitude, lng: longitude } = result.position
|
|
|
|
} |
|
|
|
// this.position = { latitude, longitude }
|
|
|
|
|
|
|
|
// console.log('this.position', this.position)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
if (navigator?.geolocation?.getCurrentPosition) { |
|
|
|
if (navigator?.geolocation?.getCurrentPosition) { |
|
|
|
navigator.geolocation.getCurrentPosition( |
|
|
|
navigator.geolocation.getCurrentPosition( |
|
|
|
position => { |
|
|
|
position => { |
|
|
@ -65,14 +48,6 @@ const instance = defineStore('user', { |
|
|
|
let { latitude, longitude } = position.coords |
|
|
|
let { latitude, longitude } = position.coords |
|
|
|
this.position = { latitude, longitude } |
|
|
|
this.position = { latitude, longitude } |
|
|
|
}, |
|
|
|
}, |
|
|
|
// function (position) {
|
|
|
|
|
|
|
|
// console.log('position', position)
|
|
|
|
|
|
|
|
// // that.$patch(state => {
|
|
|
|
|
|
|
|
// // ;({ latitude: state.position.latitude, longitude: state.position.longitude } = position.coords)
|
|
|
|
|
|
|
|
// // localStorage.setItem('position', JSON.stringify(state.position))
|
|
|
|
|
|
|
|
// // console.log(state.position, position.coords, '检测到地理位置授权')
|
|
|
|
|
|
|
|
// // })
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
error => { |
|
|
|
error => { |
|
|
|
console.log('error', error) |
|
|
|
console.log('error', error) |
|
|
|
switch (error.code) { |
|
|
|
switch (error.code) { |
|
|
|