<template>
<div
:id="id"
:style="{width:'0px',height:'0px'}"
class="m-map"/>
</template>
<script>
mounted(){
window.onmaploaded = () =>{
let map = new AMap.Map('all-map', {
center: [116.46,39.92]
})
self.map = map
window.AMap.plugin('AMap.Geolocation', function () {
var geolocation = new AMap.Geolocation({
enableHighAccuracy: true,
timeout: 10000,
buttonPosition: 'RB',
buttonOffset: new AMap.Pixel(10, 20),
zoomToAccuracy: true,
});
geolocation.getCurrentPosition(function (status, result) {
console.log(status)
if (status == 'complete') {
console.log('高德: ', `${result.position.lat},${result.position.lng}`)
self.lng = result.position.lng;
self.lat = result.position.lat;
sessionStorage.setItem('latitude',result.position.lat)
sessionStorage.setItem('longitude',result.position.lng)
self.getData()
self.$nextTick()
} else {
console.error('高德失败')
console.log(result)
}
});
self.geolocation = geolocation
});
self.map = map
}
const url = `https://webapi.amap.com/maps?v=1.4.15&key=3eb1143818def654f7e083fffe9961de&callback=onmaploaded`
let jsapi = document.createElement('script')
jsapi.charset = 'utf-8'
jsapi.src = url
document.head.appendChild(jsapi)
}
</script>
转载请注明原文地址:https://ipadbbs.8miu.com/read-42906.html