1、public文件夹下的index.html加上
<script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
2、vue页面
data () {
return {
address: {
addr: ''
},
}
},
methods:{
geoFindMe () {
const that = this
this.qq = window.qq
var geolocation = new this.qq.maps.Geolocation('OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77', 'myapp')
var options = { timeout: 8000 }
function showPosition (position) {
that.address = position // 获取到地址信息
that.src = `https://apis.map.qq.com/tools/poimarker?type=${position.type}&marker=coord:${position.lat},${position.lng};addr:${position.addr}&key=${that.key}&referer=myapp`
};
function showErr () {
alert('定位失败')
};
// 获取位置信息
geolocation.getLocation(showPosition, showErr, options)
}
}