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.getIpLocation(this.showPosition, this.showErr)
    },
    showPosition(position) {
      console.log(position)//打印位置信息
     
    },
    showErr() {
      this.getMyLocation() // 定位失败再请求定位,会导致死循环,测试使用
    },
    }

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐