|
|
|
@ -27,37 +27,20 @@ const instance = defineStore('user', { |
|
|
|
|
|
|
|
|
|
actions: { |
|
|
|
|
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(() => { |
|
|
|
|
// console.log(3)
|
|
|
|
|
let AMap = Vue.prototype.$AMap |
|
|
|
|
let geolocation = new AMap.Geolocation({ |
|
|
|
|
// enableHighAccuracy: true // 是否使用高精度定位,默认:true
|
|
|
|
|
}) |
|
|
|
|
geolocation.getCurrentPosition(function (status, result) { |
|
|
|
|
console.log('geolocation.getCurrentPosition') |
|
|
|
|
console.log('status', status) |
|
|
|
|
console.log('result', result) |
|
|
|
|
// if (status === 'complete') {
|
|
|
|
|
// let { lat: latitude, lng: longitude } = result.position
|
|
|
|
|
// this.position = { latitude, longitude }
|
|
|
|
|
// console.log('this.position', this.position)
|
|
|
|
|
// }
|
|
|
|
|
if (status === 'complete') { |
|
|
|
|
let { lat: latitude, lng: longitude } = result.position |
|
|
|
|
this.position = { latitude, longitude } |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if (navigator?.geolocation?.getCurrentPosition) { |
|
|
|
|
navigator.geolocation.getCurrentPosition( |
|
|
|
|
position => { |
|
|
|
@ -65,14 +48,6 @@ const instance = defineStore('user', { |
|
|
|
|
let { latitude, longitude } = position.coords |
|
|
|
|
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 => { |
|
|
|
|
console.log('error', error) |
|
|
|
|
switch (error.code) { |
|
|
|
|