首页 > 移动平台 > 详细

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

时间:2021-05-11 10:15:53      阅读:26      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:https://www.cnblogs.com/shangrao/p/14753780.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!