vue CLI或uniapp项目使用腾讯地图获取当前位置经纬度

1.在index.html 引入js文件

<script src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>

2.在需要页面中

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() // 定位失败再请求定位,会导致死循环,测试使用
    },
    }

 

posted @ 2021-05-11 08:42  三线码工  阅读(1067)  评论(0编辑  收藏  举报