// 從百度地圖接口獲取經緯度
getPosition2(callback) { let url = `//api.map.baidu.com/api?v=2.0&ak=${this.$config.resource.baiduAk}` this.$utils.jsonp.get(url).then(res => { // console.log("返回內容", res) let geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition( r => { console.log(r.address, r.point) if (typeof callback === "function") { callback(r); } }, { //enableHighAccuracy表示是否允許使用高精度 enableHighAccuracy: true } ); }) },
上述代碼中用到的jsonp函數參考:
https://www.jianshu.com/p/66fcfac9ea33?utm_campaign