vue 微信公众号定位+高德地图
生活随笔
收集整理的這篇文章主要介紹了
vue 微信公众号定位+高德地图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
遇到的坑,沒有搞清楚this指向導致微信定位拿到的經緯度賦值給高德地圖時,沒有賦值成功。
wxRegister() {var _this = thislet mapdata={url:location.href.split('#')[0]// url:'http://vyljd.xiaoluxueche.com/cyry/'}this.$api.wxInfo(mapdata,'application/json;charset=UTF-8',d=>{if(d.resultCode === 0){var wxdata = d.record // PS: 這里根據你接口的返回值來使用wx.config({debug: false, // 開啟調試模式appId: "wx573c7b770a66d1b1", // 必填,公眾號的唯一標識timestamp: wxdata.timessamp, // 必填,生成簽名的時間戳nonceStr: wxdata.nonceStr, // 必填,生成簽名的隨機串signature: wxdata.signature, // 必填,簽名,見附錄1jsApiList: [ // 必填,需要使用的JS接口列表,寫入自己用到的接口名稱'checkJsApi','openLocation','getLocation',]})}})wx.ready((res) => {//自動執行的wx.checkJsApi({jsApiList: ['getLocation'],success: function (res) {// ??????? alert(JSON.stringify(res));if (res.checkResult.getLocation == false) {alert('你的微信版本太低,不支持微信JS接口,請升級到最新的微信版本!');return;}}})wx.getLocation({type: 'gcj02',// 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02'success: function (res) {// 將微信定位拿到的經緯度賦值給高德地圖_this.lng = res.longitude; // 經度,浮點數,范圍為180 ~ -180。_this.lat = res.latitude; // 緯度,浮點數,范圍為90 ~ -90_this.mapCenter = [_this.lng, _this.lat];_this.showMap = false_this.loaded = true;var map = new AMap.Map('amap',{center:[111.740586, 40.854099],resizeEnable:true,zoom:10});console.log(map)var geocoder = new AMap.Geocoder({radius: 100,extensions: "all"});console.log(geocoder)// 將當前定位的坐標轉換為地址信息geocoder.getAddress([_this.lng ,_this.lat], function(status, result) {if (status === 'complete' && result.info === 'OK') {if (result && result.regeocode) {_this.$nextTick(()=>{console.log(result)_this.address = result.regeocode.formattedAddress;});}}});},cancel: function (res) {alert('用戶拒絕授權獲取地理位置');}});wx.error(function (res) {alert(res.errMsg);});})},?
總結
以上是生活随笔為你收集整理的vue 微信公众号定位+高德地图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python复制word全部内容,包括图
- 下一篇: 静态路由,缺省路由和默认网关的区别