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() // 定位失敗再請求定位,會導致死循環,測試使用
    },
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM