1.在index.html 引入js文件
<script src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
2.在需要页面中
你自己的key要去腾讯地图工具去申请
https://lbs.qq.com/webApi/component/componentGuide/componentPicker
created() {
this.getMyLocation()
// 定位获得当前位置信息
},
methods: {
getMyLocation() {
console.log(window)
var geolocation = new window.qq.maps.Geolocation('你自己的key', 'myapp')
geolocation.getLocation(this.showPosition, this.showErr)
},
showPosition(position) {
console.log(position)//打印位置信息
},
showErr() {
this.getMyLocation() // 定位失败再请求定位,会导致死循环,测试使用
},
}
标签:geolocation,vue,console,log,微信,getMyLocation,H5,window,showPosition
From: https://blog.51cto.com/u_16204378/7253856