js:
onLoad: function () {// 获取位置var that = this;// 实例化腾讯地图API核心类qqmapsdk = new QQMapWX({key: 'PKYBZ-EB4RQ-KBF5P-GMINL-C6FXK-FHBNI' // 必填});wx.getLocation({type: 'wgs84',success: function (res) {that.setData({latitude:res.latitude,longitude:res.longitude})//2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析qqmapsdk.reverseGeocoder({location: {latitude: res.latitude,longitude: res.longitude},success: function (e) {var location = e.result.address;console.log("add="+location)(为什么这一段不会打印)that.setData({location: location})}})// console.log("res==" + app.globalData.latitude)// console.log("res==" + app.globalData.longitude)that.setData({ldata: true,// latitude: latitude,// longitude: longitude})},fail: function (res) {console.log('拒绝授权')that.setData({ldata: false})}})},btnTap(e) {console.log("e+" + this.data.latitude + "," + this.data.longitude)wx.openLocation({
latitude: this.data.latitude,longitude: this.data.longitude,scale: 50})},wxml:
看着网上的例子写的,也看了文档,不知道哪里出了问题,没有效果
微信小程序开发问题解答
微信小程序开发者回答:
腾讯地图api获取并且注册相关微信小程序key没问题情况下,确保正确引入sdk,success不进的话, 去fail看一下error
本文网址:http://www.91bianli.com/kaifazhinan/75032.html